summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAvra Sengupta <asengupt@redhat.com>2014-04-02 04:18:41 +0000
committerRajesh Joseph <rjoseph@redhat.com>2014-04-02 06:02:48 -0700
commitee4e8bb5339f5517d3d248f559becfd58013a0fe (patch)
treee18b8dbe9b32bb999173199328df4df629dff1a7
parent38bfc07c9425687c8a8eed1c92d9ecd016cb00be (diff)
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 <asengupt@redhat.com> Reviewed-on: http://review.gluster.org/7381 Reviewed-by: Vijaikumar Mallikarjuna <vmallika@redhat.com> Reviewed-by: Rajesh Joseph <rjoseph@redhat.com> Tested-by: Rajesh Joseph <rjoseph@redhat.com>
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-snapshot.c34
1 files changed, 30 insertions, 4 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-snapshot.c b/xlators/mgmt/glusterd/src/glusterd-snapshot.c
index 671271a..7711bd6 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);