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