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