From ee4e8bb5339f5517d3d248f559becfd58013a0fe Mon Sep 17 00:00:00 2001 From: Avra Sengupta Date: Wed, 2 Apr 2014 04:18:41 +0000 Subject: glusterd/snapshot: Storing dynamic strings in dict Taking a duplicate of a string and storing it as a dynamic string in the dictionary, so that it is independent of the source string. Change-Id: Ib7d18ab8e7342fd71dad80d03259f76a5d2bd66d BUG: 1077196 Signed-off-by: Avra Sengupta Reviewed-on: http://review.gluster.org/7381 Reviewed-by: Vijaikumar Mallikarjuna Reviewed-by: Rajesh Joseph Tested-by: Rajesh Joseph --- xlators/mgmt/glusterd/src/glusterd-snapshot.c | 34 +++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) (limited to 'xlators/mgmt') diff --git a/xlators/mgmt/glusterd/src/glusterd-snapshot.c b/xlators/mgmt/glusterd/src/glusterd-snapshot.c index 671271aea..7711bd61a 100644 --- a/xlators/mgmt/glusterd/src/glusterd-snapshot.c +++ b/xlators/mgmt/glusterd/src/glusterd-snapshot.c @@ -2090,6 +2090,7 @@ glusterd_handle_snapshot_status (rpcsvc_request_t *req, glusterd_op_t op, int ret = -1; char *volname = NULL; char *snapname = NULL; + char *buf = NULL; glusterd_conf_t *conf = NULL; xlator_t *this = NULL; int32_t cmd = -1; @@ -2127,14 +2128,22 @@ glusterd_handle_snapshot_status (rpcsvc_request_t *req, glusterd_op_t op, list_for_each_entry (snap, &conf->snapshots, snap_list) { snprintf (key, sizeof (key), "snapname%d", i); - ret = dict_set_str (dict, key, snap->snapname); + buf = gf_strdup (snap->snapname); + if (!buf) { + ret = -1; + goto out; + } + ret = dict_set_dynstr (dict, key, buf); if (ret) { gf_log (this->name, GF_LOG_ERROR, "Could not save snapname (%s) " "in the dictionary", snap->snapname); + GF_FREE (buf); goto out; } + + buf = NULL; i++; } @@ -2195,13 +2204,22 @@ glusterd_handle_snapshot_status (rpcsvc_request_t *req, glusterd_op_t op, &volinfo->snap_volumes, snapvol_list) { snprintf (key, sizeof (key), "snapname%d", i); - ret = dict_set_str (dict, key, - snap_volinfo->snapshot->snapname); + buf = gf_strdup + (snap_volinfo->snapshot->snapname); + if (!buf) { + ret = -1; + goto out; + } + + ret = dict_set_dynstr (dict, key, buf); if (ret) { gf_log (this->name, GF_LOG_ERROR, "Could not save snapname"); + GF_FREE (buf); goto out; } + + buf = NULL; i++; } @@ -2265,6 +2283,7 @@ glusterd_handle_snapshot_restore (rpcsvc_request_t *req, glusterd_op_t op, { int ret = -1; char *snapname = NULL; + char *buf = NULL; glusterd_conf_t *conf = NULL; xlator_t *this = NULL; glusterd_snap_t *snap = NULL; @@ -2299,12 +2318,19 @@ glusterd_handle_snapshot_restore (rpcsvc_request_t *req, glusterd_op_t op, list_for_each_entry (snap_volinfo, &snap->volumes, vol_list) { i++; snprintf (key, sizeof (key), "volname%d", i); - ret = dict_set_str (dict, key, snap_volinfo->parent_volname); + buf = gf_strdup (snap_volinfo->parent_volname); + if (!buf) { + ret = -1; + goto out; + } + ret = dict_set_dynstr (dict, key, buf); if (ret) { gf_log (this->name, GF_LOG_ERROR, "Could not set " "parent volume name"); + GF_FREE (buf); goto out; } + buf = NULL; } ret = dict_set_int32 (dict, "volcount", i); -- cgit