Blob Blame History Raw
From 5b57b686984498eee09ce1a5f27eef6a14e4387e Mon Sep 17 00:00:00 2001
From: Mohit Agrawal <moagrawa@redhat.com>
Date: Wed, 6 Mar 2019 12:55:56 +0530
Subject: [PATCH 533/534] glusterd: glusterd memory leak while running "gluster
 v profile" in a loop

Problem: glusterd has memory leak while running "gluster v profile"
         in a loop

Solution: Resolve leak code path to avoid leak

> Change-Id: Id608703ff6d0ad34ed8f921a5d25544e24cfadcd
> fixes: bz#1685414
> Cherry pick from commit 9374484917466dff4688d96ff7faa0de1c804a6c
> Reviewed on upstream link https://review.gluster.org/#/c/glusterfs/+/22301/

Change-Id: I874a0e9947913c201c67b78aaaa982d1fae78b46
BUG: 1684648
Signed-off-by: Mohit Agrawal <moagrawa@redhat.com>
Reviewed-on: https://code.engineering.redhat.com/gerrit/164609
Tested-by: RHGS Build Bot <nigelb@redhat.com>
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
---
 xlators/mgmt/glusterd/src/glusterd-mgmt.c   | 5 +++--
 xlators/mgmt/glusterd/src/glusterd-syncop.c | 4 +++-
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/xlators/mgmt/glusterd/src/glusterd-mgmt.c b/xlators/mgmt/glusterd/src/glusterd-mgmt.c
index 275059c..e176288 100644
--- a/xlators/mgmt/glusterd/src/glusterd-mgmt.c
+++ b/xlators/mgmt/glusterd/src/glusterd-mgmt.c
@@ -1380,8 +1380,9 @@ out:
         if (rsp.op_errstr)
                 free (rsp.op_errstr);
 
-        if (rsp.dict.dict_val)
-                free (rsp.dict.dict_val);
+        if (rsp_dict)
+                dict_unref (rsp_dict);
+
         GF_FREE (peerid);
         /* req->rpc_status set to -1 means, STACK_DESTROY will be called from
          * the caller function.
diff --git a/xlators/mgmt/glusterd/src/glusterd-syncop.c b/xlators/mgmt/glusterd/src/glusterd-syncop.c
index 7baef64..3b7fa8b 100644
--- a/xlators/mgmt/glusterd/src/glusterd-syncop.c
+++ b/xlators/mgmt/glusterd/src/glusterd-syncop.c
@@ -1707,6 +1707,7 @@ gd_brick_op_phase (glusterd_op_t op, dict_t *op_ctx, dict_t *req_dict,
                    char **op_errstr)
 {
         glusterd_pending_node_t *pending_node = NULL;
+        glusterd_pending_node_t *tmp = NULL;
         struct cds_list_head    selected = {0,};
         xlator_t                *this = NULL;
         int                     brick_count = 0;
@@ -1742,7 +1743,7 @@ gd_brick_op_phase (glusterd_op_t op, dict_t *op_ctx, dict_t *req_dict,
         rsp_dict = NULL;
 
         brick_count = 0;
-        cds_list_for_each_entry (pending_node, &selected, list) {
+        cds_list_for_each_entry_safe (pending_node, tmp, &selected, list) {
                 rpc = glusterd_pending_node_get_rpc (pending_node);
                 if (!rpc) {
                         if (pending_node->type == GD_NODE_REBALANCE) {
@@ -1792,6 +1793,7 @@ gd_brick_op_phase (glusterd_op_t op, dict_t *op_ctx, dict_t *req_dict,
 
                 brick_count++;
                 glusterd_pending_node_put_rpc (pending_node);
+                GF_FREE(pending_node);
         }
 
         pending_node = NULL;
-- 
1.8.3.1