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