50dc83
From 5f304e003cc24ff7877ab51bdfded0dbf8ec581b Mon Sep 17 00:00:00 2001
50dc83
From: N Balachandran <nbalacha@redhat.com>
50dc83
Date: Fri, 21 Jun 2019 09:04:19 +0530
50dc83
Subject: [PATCH 222/255] cluster/dht:  Fixed a memleak in dht_rename_cbk
50dc83
50dc83
Fixed a memleak in dht_rename_cbk when creating
50dc83
a linkto file.
50dc83
50dc83
upstream: https://review.gluster.org/#/c/glusterfs/+/22912/
50dc83
50dc83
>Change-Id: I705adef3cb79e33806520fc2b15558e90e2c211c
50dc83
>fixes: bz#1722698
50dc83
>Signed-off-by: N Balachandran <nbalacha@redhat.com>
50dc83
50dc83
BUG:1722512
50dc83
Change-Id: I8450cac82a0e1611e698ffac476ea5516e614236
50dc83
Signed-off-by: N Balachandran <nbalacha@redhat.com>
50dc83
Reviewed-on: https://code.engineering.redhat.com/gerrit/175181
50dc83
Tested-by: RHGS Build Bot <nigelb@redhat.com>
50dc83
Reviewed-by: Susant Palai <spalai@redhat.com>
50dc83
---
50dc83
 xlators/cluster/dht/src/dht-rename.c | 44 +++++++++++++++++++++++++++---------
50dc83
 1 file changed, 33 insertions(+), 11 deletions(-)
50dc83
50dc83
diff --git a/xlators/cluster/dht/src/dht-rename.c b/xlators/cluster/dht/src/dht-rename.c
50dc83
index 893b451..5ba2373 100644
50dc83
--- a/xlators/cluster/dht/src/dht-rename.c
50dc83
+++ b/xlators/cluster/dht/src/dht-rename.c
50dc83
@@ -1009,9 +1009,11 @@ dht_rename_links_create_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
50dc83
 {
50dc83
     xlator_t *prev = NULL;
50dc83
     dht_local_t *local = NULL;
50dc83
+    call_frame_t *main_frame = NULL;
50dc83
 
50dc83
     prev = cookie;
50dc83
     local = frame->local;
50dc83
+    main_frame = local->main_frame;
50dc83
 
50dc83
     /* TODO: Handle this case in lookup-optimize */
50dc83
     if (op_ret == -1) {
50dc83
@@ -1024,7 +1026,8 @@ dht_rename_links_create_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
50dc83
         dht_linkfile_attr_heal(frame, this);
50dc83
     }
50dc83
 
50dc83
-    dht_rename_unlink(frame, this);
50dc83
+    dht_rename_unlink(main_frame, this);
50dc83
+    DHT_STACK_DESTROY(frame);
50dc83
     return 0;
50dc83
 }
50dc83
 
50dc83
@@ -1040,7 +1043,8 @@ dht_rename_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
50dc83
     xlator_t *src_cached = NULL;
50dc83
     xlator_t *dst_hashed = NULL;
50dc83
     xlator_t *dst_cached = NULL;
50dc83
-    loc_t link_loc = {0};
50dc83
+    call_frame_t *link_frame = NULL;
50dc83
+    dht_local_t *link_local = NULL;
50dc83
 
50dc83
     local = frame->local;
50dc83
     prev = cookie;
50dc83
@@ -1110,18 +1114,36 @@ dht_rename_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
50dc83
 
50dc83
     /* Create the linkto file for the dst file */
50dc83
     if ((src_cached == dst_cached) && (dst_hashed != dst_cached)) {
50dc83
-        loc_copy(&link_loc, &local->loc2);
50dc83
-        if (link_loc.inode)
50dc83
-            inode_unref(link_loc.inode);
50dc83
-        link_loc.inode = inode_ref(local->loc.inode);
50dc83
-        gf_uuid_copy(local->gfid, local->loc.inode->gfid);
50dc83
-        gf_uuid_copy(link_loc.gfid, local->loc.inode->gfid);
50dc83
-
50dc83
-        dht_linkfile_create(frame, dht_rename_links_create_cbk, this,
50dc83
-                            src_cached, dst_hashed, &link_loc);
50dc83
+        link_frame = copy_frame(frame);
50dc83
+        if (!link_frame) {
50dc83
+            goto unlink;
50dc83
+        }
50dc83
+
50dc83
+        /* fop value sent as maxvalue because it is not used
50dc83
+         * anywhere in this case */
50dc83
+        link_local = dht_local_init(link_frame, &local->loc2, NULL,
50dc83
+                                    GF_FOP_MAXVALUE);
50dc83
+        if (!link_local) {
50dc83
+            goto unlink;
50dc83
+        }
50dc83
+
50dc83
+        if (link_local->loc.inode)
50dc83
+            inode_unref(link_local->loc.inode);
50dc83
+        link_local->loc.inode = inode_ref(local->loc.inode);
50dc83
+        link_local->main_frame = frame;
50dc83
+        link_local->stbuf = local->stbuf;
50dc83
+        gf_uuid_copy(link_local->gfid, local->loc.inode->gfid);
50dc83
+
50dc83
+        dht_linkfile_create(link_frame, dht_rename_links_create_cbk, this,
50dc83
+                            src_cached, dst_hashed, &link_local->loc);
50dc83
         return 0;
50dc83
     }
50dc83
 
50dc83
+unlink:
50dc83
+
50dc83
+    if (link_frame) {
50dc83
+        DHT_STACK_DESTROY(link_frame);
50dc83
+    }
50dc83
     dht_rename_unlink(frame, this);
50dc83
     return 0;
50dc83
 
50dc83
-- 
50dc83
1.8.3.1
50dc83