From 547563d284e40fc9cdecda4c1ecde372ed1a01c5 Mon Sep 17 00:00:00 2001 From: Mohammed Rafi KC Date: Fri, 3 Jun 2016 12:44:14 +0530 Subject: glusterd/snapshot: free resource from the owner of memory We are freeing memory from a function which is not the owner of the memory. Free should happen from the owner of resources. Change-Id: If8772ba27f9eb65881dcdddde8d7dc431c1c0ee8 BUG: 1341796 Signed-off-by: Mohammed Rafi KC Reviewed-on: http://review.gluster.org/14634 NetBSD-regression: NetBSD Build System CentOS-regression: Gluster Build System Smoke: Gluster Build System Reviewed-by: Jeff Darcy --- xlators/mgmt/glusterd/src/glusterd-snapshot.c | 29 +++++++-------------------- 1 file changed, 7 insertions(+), 22 deletions(-) (limited to 'xlators/mgmt') diff --git a/xlators/mgmt/glusterd/src/glusterd-snapshot.c b/xlators/mgmt/glusterd/src/glusterd-snapshot.c index 7967722d798..5d5bdead416 100644 --- a/xlators/mgmt/glusterd/src/glusterd-snapshot.c +++ b/xlators/mgmt/glusterd/src/glusterd-snapshot.c @@ -5179,16 +5179,6 @@ glusterd_snap_clear_unsupported_opt (glusterd_volinfo_t *volinfo, ret = 0; out: - if (ret) { - for (i = 0; unsupported_opt[i].key; i++) { - if (unsupported_opt[i].value) { - /* Freeing the memory */ - GF_FREE (unsupported_opt[i].value); - unsupported_opt[i].value = NULL; - } - } - } - return ret; } @@ -5212,20 +5202,11 @@ glusterd_snap_set_unsupported_opt (glusterd_volinfo_t *volinfo, GD_MSG_DICT_SET_FAILED, "dict set failed"); goto out; } + unsupported_opt[i].value = NULL; } ret = 0; out: - if (ret) { - for (; unsupported_opt[i].key; i++) { - if (unsupported_opt[i].value) { - /* Freeing the memory */ - GF_FREE (unsupported_opt[i].value); - unsupported_opt[i].value = NULL; - } - } - } - return ret; } @@ -5247,8 +5228,9 @@ glusterd_do_snap_vol (glusterd_volinfo_t *origin_vol, glusterd_snap_t *snap, int64_t brick_order = 0; char *clonename = NULL; gf_boolean_t conf_present = _gf_false; + int i = 0; - struct gd_snap_unsupported_opt_t unsupported_opt[] = { + struct gd_snap_unsupported_opt_t unsupported_opt[] = { {.key = VKEY_FEATURES_QUOTA, .value = NULL}, {.key = VKEY_FEATURES_INODE_QUOTA, @@ -5259,7 +5241,7 @@ glusterd_do_snap_vol (glusterd_volinfo_t *origin_vol, glusterd_snap_t *snap, .value = NULL}, {.key = NULL, .value = NULL} - }; + }; this = THIS; GF_ASSERT (this); @@ -5468,6 +5450,9 @@ reset_option: } out: if (ret) { + for (i = 0; unsupported_opt[i].key; i++) + GF_FREE (unsupported_opt[i].value); + if (snap_vol) glusterd_snap_volume_remove (rsp_dict, snap_vol, _gf_true, _gf_true); -- cgit