c460ee
From 59c05230c0df58765e30553c66bbcc0c9965d362 Mon Sep 17 00:00:00 2001
c460ee
From: nik-redhat <nladha@redhat.com>
c460ee
Date: Tue, 11 Aug 2020 23:12:26 +0530
c460ee
Subject: [PATCH 597/610] glusterd: memory deallocated twice
c460ee
c460ee
Issue:
c460ee
If the the pointer tmptier is destroyed in the function
c460ee
code it still it checks for the same in the out label.
c460ee
And tries to destroy the same pointer again.
c460ee
c460ee
Fix:
c460ee
So, instead of passing the ptr by value, if we
c460ee
pass it by reference then, on making the ptr in the
c460ee
function the value will persist, in the calling
c460ee
function and next time when the gf_store_iter_destory()
c460ee
is called it won't try to free the ptr again.
c460ee
c460ee
CID: 1430122
c460ee
c460ee
>Updates: #1060
c460ee
c460ee
>Change-Id: I019cea8e301c7cc87be792c03b58722fc96f04ef
c460ee
>Signed-off-by: nik-redhat <nladha@redhat.com>
c460ee
c460ee
Upstream link: https://review.gluster.org/c/glusterfs/+/24855
c460ee
BUG: 1997447
c460ee
c460ee
Change-Id: Ib403efd08d47a69d25f291ae61c9cbfcaaa05da8
c460ee
Signed-off-by: nik-redhat <nladha@redhat.com>
c460ee
Reviewed-on: https://code.engineering.redhat.com/gerrit/c/rhs-glusterfs/+/280076
c460ee
Tested-by: RHGS Build Bot <nigelb@redhat.com>
c460ee
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
c460ee
---
c460ee
 libglusterfs/src/glusterfs/store.h         |  2 +-
c460ee
 libglusterfs/src/store.c                   | 12 +++++++-----
c460ee
 xlators/mgmt/glusterd/src/glusterd-store.c | 16 ++++++++--------
c460ee
 3 files changed, 16 insertions(+), 14 deletions(-)
c460ee
c460ee
diff --git a/libglusterfs/src/glusterfs/store.h b/libglusterfs/src/glusterfs/store.h
c460ee
index 68a20ad..76af2df 100644
c460ee
--- a/libglusterfs/src/glusterfs/store.h
c460ee
+++ b/libglusterfs/src/glusterfs/store.h
c460ee
@@ -93,7 +93,7 @@ int32_t
c460ee
 gf_store_iter_get_matching(gf_store_iter_t *iter, char *key, char **value);
c460ee
 
c460ee
 int32_t
c460ee
-gf_store_iter_destroy(gf_store_iter_t *iter);
c460ee
+gf_store_iter_destroy(gf_store_iter_t **iter);
c460ee
 
c460ee
 char *
c460ee
 gf_store_strerror(gf_store_op_errno_t op_errno);
c460ee
diff --git a/libglusterfs/src/store.c b/libglusterfs/src/store.c
c460ee
index 3af627a..e4931bf 100644
c460ee
--- a/libglusterfs/src/store.c
c460ee
+++ b/libglusterfs/src/store.c
c460ee
@@ -606,23 +606,25 @@ out:
c460ee
 }
c460ee
 
c460ee
 int32_t
c460ee
-gf_store_iter_destroy(gf_store_iter_t *iter)
c460ee
+gf_store_iter_destroy(gf_store_iter_t **iter)
c460ee
 {
c460ee
     int32_t ret = -1;
c460ee
 
c460ee
-    if (!iter)
c460ee
+    if (!(*iter))
c460ee
         return 0;
c460ee
 
c460ee
     /* gf_store_iter_new will not return a valid iter object with iter->file
c460ee
      * being NULL*/
c460ee
-    ret = fclose(iter->file);
c460ee
+    ret = fclose((*iter)->file);
c460ee
     if (ret)
c460ee
         gf_msg("", GF_LOG_ERROR, errno, LG_MSG_FILE_OP_FAILED,
c460ee
                "Unable"
c460ee
                " to close file: %s, ret: %d",
c460ee
-               iter->filepath, ret);
c460ee
+               (*iter)->filepath, ret);
c460ee
+
c460ee
+    GF_FREE(*iter);
c460ee
+    *iter = NULL;
c460ee
 
c460ee
-    GF_FREE(iter);
c460ee
     return ret;
c460ee
 }
c460ee
 
c460ee
diff --git a/xlators/mgmt/glusterd/src/glusterd-store.c b/xlators/mgmt/glusterd/src/glusterd-store.c
c460ee
index a8651d8..e027575 100644
c460ee
--- a/xlators/mgmt/glusterd/src/glusterd-store.c
c460ee
+++ b/xlators/mgmt/glusterd/src/glusterd-store.c
c460ee
@@ -2576,7 +2576,7 @@ glusterd_store_retrieve_snapd(glusterd_volinfo_t *volinfo)
c460ee
     ret = 0;
c460ee
 
c460ee
 out:
c460ee
-    if (gf_store_iter_destroy(iter)) {
c460ee
+    if (gf_store_iter_destroy(&iter)) {
c460ee
         gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_STORE_ITER_DESTROY_FAIL,
c460ee
                "Failed to destroy store iter");
c460ee
         ret = -1;
c460ee
@@ -2895,13 +2895,13 @@ glusterd_store_retrieve_bricks(glusterd_volinfo_t *volinfo)
c460ee
     ret = 0;
c460ee
 
c460ee
 out:
c460ee
-    if (gf_store_iter_destroy(tmpiter)) {
c460ee
+    if (gf_store_iter_destroy(&tmpiter)) {
c460ee
         gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_STORE_ITER_DESTROY_FAIL,
c460ee
                "Failed to destroy store iter");
c460ee
         ret = -1;
c460ee
     }
c460ee
 
c460ee
-    if (gf_store_iter_destroy(iter)) {
c460ee
+    if (gf_store_iter_destroy(&iter)) {
c460ee
         gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_STORE_ITER_DESTROY_FAIL,
c460ee
                "Failed to destroy store iter");
c460ee
         ret = -1;
c460ee
@@ -3067,7 +3067,7 @@ glusterd_store_retrieve_node_state(glusterd_volinfo_t *volinfo)
c460ee
     ret = 0;
c460ee
 
c460ee
 out:
c460ee
-    if (gf_store_iter_destroy(iter)) {
c460ee
+    if (gf_store_iter_destroy(&iter)) {
c460ee
         gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_STORE_ITER_DESTROY_FAIL,
c460ee
                "Failed to destroy store iter");
c460ee
         ret = -1;
c460ee
@@ -3379,7 +3379,7 @@ glusterd_store_update_volinfo(glusterd_volinfo_t *volinfo)
c460ee
     ret = 0;
c460ee
 
c460ee
 out:
c460ee
-    if (gf_store_iter_destroy(iter)) {
c460ee
+    if (gf_store_iter_destroy(&iter)) {
c460ee
         gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_STORE_ITER_DESTROY_FAIL,
c460ee
                "Failed to destroy store iter");
c460ee
         ret = -1;
c460ee
@@ -3574,7 +3574,7 @@ glusterd_store_retrieve_options(xlator_t *this)
c460ee
         goto out;
c460ee
     ret = 0;
c460ee
 out:
c460ee
-    (void)gf_store_iter_destroy(iter);
c460ee
+    (void)gf_store_iter_destroy(&iter);
c460ee
     gf_store_handle_destroy(shandle);
c460ee
     return ret;
c460ee
 }
c460ee
@@ -4026,7 +4026,7 @@ glusterd_store_update_snap(glusterd_snap_t *snap)
c460ee
     ret = 0;
c460ee
 
c460ee
 out:
c460ee
-    if (gf_store_iter_destroy(iter)) {
c460ee
+    if (gf_store_iter_destroy(&iter)) {
c460ee
         gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_STORE_ITER_DESTROY_FAIL,
c460ee
                "Failed to destroy store iter");
c460ee
         ret = -1;
c460ee
@@ -4774,7 +4774,7 @@ glusterd_store_retrieve_peers(xlator_t *this)
c460ee
         is_ok = _gf_true;
c460ee
 
c460ee
     next:
c460ee
-        (void)gf_store_iter_destroy(iter);
c460ee
+        (void)gf_store_iter_destroy(&iter);
c460ee
 
c460ee
         if (!is_ok) {
c460ee
             gf_log(this->name, GF_LOG_WARNING,
c460ee
-- 
c460ee
1.8.3.1
c460ee