diff options
author | Avra Sengupta <asengupt@redhat.com> | 2016-10-18 12:52:36 +0530 |
---|---|---|
committer | Rajesh Joseph <rjoseph@redhat.com> | 2016-10-25 00:16:43 -0700 |
commit | 48a4c4e525665115f7e8c478d3bf51764427378d (patch) | |
tree | 48b920d682695e888165e2d7e80c5671e35d5028 | |
parent | a6b63e11b7758cf1bfcb67985e25ec02845f0995 (diff) |
snapshot: Fix for memory leaks in snapshot code path
Change-Id: Idc2cb16574d166e3c0ee1f7c3a485f1acb19fc8c
BUG: 1386088
Signed-off-by: Avra Sengupta <asengupt@redhat.com>
Reviewed-on: http://review.gluster.org/15668
NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
Smoke: Gluster Build System <jenkins@build.gluster.org>
Reviewed-by: Rajesh Joseph <rjoseph@redhat.com>
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-mgmt.c | 4 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-snapshot.c | 38 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-utils.c | 17 |
3 files changed, 47 insertions, 12 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-mgmt.c b/xlators/mgmt/glusterd/src/glusterd-mgmt.c index a5d22e4e265..85c98481042 100644 --- a/xlators/mgmt/glusterd/src/glusterd-mgmt.c +++ b/xlators/mgmt/glusterd/src/glusterd-mgmt.c @@ -1339,6 +1339,10 @@ out: gd_mgmt_v3_collate_errors (args, op_ret, op_errno, rsp.op_errstr, GLUSTERD_MGMT_V3_COMMIT, *peerid, rsp.uuid); GF_FREE (peerid); + + if (rsp.op_errstr) + free (rsp.op_errstr); + /* req->rpc_status set to -1 means, STACK_DESTROY will be called from * the caller function. */ diff --git a/xlators/mgmt/glusterd/src/glusterd-snapshot.c b/xlators/mgmt/glusterd/src/glusterd-snapshot.c index dbaa1d685aa..dee31563d38 100644 --- a/xlators/mgmt/glusterd/src/glusterd-snapshot.c +++ b/xlators/mgmt/glusterd/src/glusterd-snapshot.c @@ -2106,6 +2106,7 @@ glusterd_snap_create_clone_common_prevalidate (dict_t *rsp_dict, int flags, int clone, uint32_t *op_errno) { char *device = NULL; + char *orig_device = NULL; char key[PATH_MAX] = ""; int ret = -1; int64_t i = 1; @@ -2171,9 +2172,9 @@ glusterd_snap_create_clone_common_prevalidate (dict_t *rsp_dict, int flags, } - device = glusterd_get_brick_mount_device - (brickinfo->path); - if (!device) { + orig_device = glusterd_get_brick_mount_device + (brickinfo->path); + if (!orig_device) { snprintf (err_str, PATH_MAX, "getting device name for the brick " "%s:%s failed", brickinfo->hostname, @@ -2182,7 +2183,7 @@ glusterd_snap_create_clone_common_prevalidate (dict_t *rsp_dict, int flags, goto out; } if (!clone) { - if (!glusterd_is_thinp_brick (device, op_errno)) { + if (!glusterd_is_thinp_brick (orig_device, op_errno)) { snprintf (err_str, PATH_MAX, "Snapshot is supported only for " "thin provisioned LV. Ensure that " @@ -2190,10 +2191,10 @@ glusterd_snap_create_clone_common_prevalidate (dict_t *rsp_dict, int flags, "provisioned LV.", volinfo->volname); ret = -1; goto out; - } + } } - device = glusterd_build_snap_device_path (device, + device = glusterd_build_snap_device_path (orig_device, snap_volname, brick_count); if (!device) { @@ -2206,18 +2207,19 @@ glusterd_snap_create_clone_common_prevalidate (dict_t *rsp_dict, int flags, goto out; } + GF_FREE(orig_device); + orig_device = NULL; + snprintf (key, sizeof(key), "vol%"PRId64".brick_snapdevice%"PRId64, i, brick_count); - ret = dict_set_dynstr (rsp_dict, key, device); + ret = dict_set_dynstr_with_alloc (rsp_dict, key, device); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, "Failed to set %s", key); - GF_FREE (device); goto out; } - device = NULL; ret = glusterd_update_mntopts (brickinfo->path, brickinfo); @@ -2287,6 +2289,10 @@ glusterd_snap_create_clone_common_prevalidate (dict_t *rsp_dict, int flags, } brick_count++; brick_order++; + if (device) { + GF_FREE(device); + device = NULL; + } } snprintf (key, sizeof(key) - 1, "vol%"PRId64"_brickcount", volcount); ret = dict_set_int64 (rsp_dict, key, brick_count); @@ -2298,8 +2304,11 @@ glusterd_snap_create_clone_common_prevalidate (dict_t *rsp_dict, int flags, } ret = 0; out: + if (orig_device) + GF_FREE(orig_device); + if (device) - GF_FREE (device); + GF_FREE (device); return ret; @@ -2831,6 +2840,9 @@ glusterd_do_lvm_snapshot_remove (glusterd_volinfo_t *snap_vol, } out: + if (mnt_pt) + GF_FREE(mnt_pt); + return ret; } @@ -4723,6 +4735,9 @@ glusterd_take_lvm_snapshot (glusterd_brickinfo_t *brickinfo, } out: + if (origin_device) + GF_FREE (origin_device); + return ret; } @@ -7360,6 +7375,9 @@ out: GF_FREE (value); } + if (device) + GF_FREE (device); + return ret; } diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c index 48232ffdaa8..d916444a9b2 100644 --- a/xlators/mgmt/glusterd/src/glusterd-utils.c +++ b/xlators/mgmt/glusterd/src/glusterd-utils.c @@ -866,6 +866,8 @@ glusterd_brickinfo_delete (glusterd_brickinfo_t *brickinfo) cds_list_del_init (&brickinfo->brick_list); + (void) gf_store_handle_destroy (brickinfo->shandle); + GF_FREE (brickinfo->logfile); GF_FREE (brickinfo); @@ -927,6 +929,9 @@ glusterd_volinfo_delete (glusterd_volinfo_t *volinfo) dict_unref (volinfo->rebal.dict); gf_store_handle_destroy (volinfo->quota_conf_shandle); + gf_store_handle_destroy (volinfo->shandle); + gf_store_handle_destroy (volinfo->node_state_shandle); + gf_store_handle_destroy (volinfo->snapd.handle); glusterd_auth_cleanup (volinfo); @@ -1055,6 +1060,9 @@ glusterd_get_brick_mount_dir (char *brickpath, char *hostname, char *mount_dir) } out: + if (mnt_pt) + GF_FREE(mnt_pt); + gf_msg_trace (this->name, 0, "Returning %d", ret); return ret; } @@ -5597,7 +5605,8 @@ glusterd_add_brick_mount_details (glusterd_brickinfo_t *brickinfo, ret = dict_set_dynstr_with_alloc (dict, key, entry->mnt_opts); out: - GF_FREE (mnt_pt); + if (mnt_pt) + GF_FREE (mnt_pt); return ret; } @@ -5640,6 +5649,9 @@ glusterd_get_brick_mount_device (char *brick_path) device = gf_strdup (entry->mnt_fsname); out: + if (mnt_pt) + GF_FREE(mnt_pt); + return device; } @@ -10828,7 +10840,8 @@ glusterd_update_mntopts (char *brick_path, glusterd_brickinfo_t *brickinfo) ret = 0; out: - GF_FREE (mnt_pt); + if (mnt_pt) + GF_FREE (mnt_pt); return ret; } |