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