summaryrefslogtreecommitdiffstats
path: root/xlators/mgmt/glusterd/src/glusterd-snapshot.c
diff options
context:
space:
mode:
authorAvra Sengupta <asengupt@redhat.com>2016-10-18 12:52:36 +0530
committerRajesh Joseph <rjoseph@redhat.com>2016-10-25 00:16:43 -0700
commit48a4c4e525665115f7e8c478d3bf51764427378d (patch)
tree48b920d682695e888165e2d7e80c5671e35d5028 /xlators/mgmt/glusterd/src/glusterd-snapshot.c
parenta6b63e11b7758cf1bfcb67985e25ec02845f0995 (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>
Diffstat (limited to 'xlators/mgmt/glusterd/src/glusterd-snapshot.c')
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-snapshot.c38
1 files changed, 28 insertions, 10 deletions
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;
}