diff options
author | nik-redhat <nladha@redhat.com> | 2020-08-11 23:12:26 +0530 |
---|---|---|
committer | MOHIT AGRAWAL <moagrawa@redhat.com> | 2020-08-18 04:18:21 +0000 |
commit | f5f94e574a8e27e4a6665567db30b82618115694 (patch) | |
tree | f596d4356eb0d05741d29de5789a9b38ca509d72 /libglusterfs | |
parent | b86d95dfa3ba8f08dc2ef8c6e6b0dcd5ea4314b7 (diff) |
glusterd: memory deallocated twice
Issue:
If the the pointer tmptier is destroyed in the function
code it still it checks for the same in the out label.
And tries to destroy the same pointer again.
Fix:
So, instead of passing the ptr by value, if we
pass it by reference then, on making the ptr in the
function the value will persist, in the calling
function and next time when the gf_store_iter_destory()
is called it won't try to free the ptr again.
CID: 1430122
Updates: #1060
Change-Id: I019cea8e301c7cc87be792c03b58722fc96f04ef
Signed-off-by: nik-redhat <nladha@redhat.com>
Diffstat (limited to 'libglusterfs')
-rw-r--r-- | libglusterfs/src/glusterfs/store.h | 2 | ||||
-rw-r--r-- | libglusterfs/src/store.c | 12 |
2 files changed, 7 insertions, 7 deletions
diff --git a/libglusterfs/src/glusterfs/store.h b/libglusterfs/src/glusterfs/store.h index c8be544e164..a1f70c7b840 100644 --- a/libglusterfs/src/glusterfs/store.h +++ b/libglusterfs/src/glusterfs/store.h @@ -95,7 +95,7 @@ int32_t gf_store_iter_get_matching(gf_store_iter_t *iter, char *key, char **value); int32_t -gf_store_iter_destroy(gf_store_iter_t *iter); +gf_store_iter_destroy(gf_store_iter_t **iter); char * gf_store_strerror(gf_store_op_errno_t op_errno); diff --git a/libglusterfs/src/store.c b/libglusterfs/src/store.c index 74cf5459c3c..5c316b9291a 100644 --- a/libglusterfs/src/store.c +++ b/libglusterfs/src/store.c @@ -649,24 +649,24 @@ out: } int32_t -gf_store_iter_destroy(gf_store_iter_t *iter) +gf_store_iter_destroy(gf_store_iter_t **iter) { int32_t ret = -1; - if (!iter) + if (!(*iter)) return 0; /* gf_store_iter_new will not return a valid iter object with iter->file * being NULL*/ - ret = fclose(iter->file); + ret = fclose((*iter)->file); if (ret) gf_msg("", GF_LOG_ERROR, errno, LG_MSG_FILE_OP_FAILED, "Unable" " to close file: %s, ret: %d", - iter->filepath, ret); + (*iter)->filepath, ret); - GF_FREE(iter); - iter = NULL; + GF_FREE(*iter); + *iter = NULL; return ret; } |