summaryrefslogtreecommitdiffstats
path: root/xlators/cluster/afr/src/pump.c
diff options
context:
space:
mode:
authorKrishnan P <kp@gluster.com>2011-07-12 01:51:17 +0000
committerAnand Avati <avati@gluster.com>2011-07-12 02:12:58 -0700
commit03df277c7880541570107bbaa7f91e5cf7ad5a69 (patch)
treebf9d1e0dbd302dd2c6a05ab7b27eadf070db8e53 /xlators/cluster/afr/src/pump.c
parent1f5119627b278b98518afb68a7eb88752932976c (diff)
pump, afr: dict related memory fixes.
Signed-off-by: Krishnan Parthasarathi <kp@gluster.com> Signed-off-by: Anand Avati <avati@gluster.com> BUG: 2489 (GlusterFS crashing with replace-brick) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=2489
Diffstat (limited to 'xlators/cluster/afr/src/pump.c')
-rw-r--r--xlators/cluster/afr/src/pump.c52
1 files changed, 36 insertions, 16 deletions
diff --git a/xlators/cluster/afr/src/pump.c b/xlators/cluster/afr/src/pump.c
index 873fc8bde..48ce2c945 100644
--- a/xlators/cluster/afr/src/pump.c
+++ b/xlators/cluster/afr/src/pump.c
@@ -893,7 +893,8 @@ pump_initiate_sink_connect (call_frame_t *frame, xlator_t *this)
afr_local_t *local = NULL;
afr_private_t *priv = NULL;
dict_t *dict = NULL;
- char *dst_brick = NULL;
+ data_t *data = NULL;
+ char *clnt_cmd = NULL;
loc_t loc = {0};
int ret = 0;
@@ -905,8 +906,9 @@ pump_initiate_sink_connect (call_frame_t *frame, xlator_t *this)
build_root_loc (priv->root_inode, &loc);
- ret = dict_get_str (local->dict, PUMP_CMD_START, &dst_brick);
- if (ret < 0) {
+ data = data_ref (dict_get (local->dict, PUMP_CMD_START));
+ if (!data) {
+ ret = -1;
gf_log (this->name, GF_LOG_ERROR,
"Could not get destination brick value");
goto out;
@@ -914,17 +916,22 @@ pump_initiate_sink_connect (call_frame_t *frame, xlator_t *this)
dict = dict_new ();
if (!dict) {
- gf_log (this->name, GF_LOG_ERROR,
- "Out of memory");
ret = -1;
goto out;
}
- GF_ASSERT (dst_brick);
- gf_log (this->name, GF_LOG_DEBUG,
- "Got destination brick as %s", dst_brick);
+ clnt_cmd = GF_CALLOC (1, data->len+1, gf_common_mt_char);
+ if (!clnt_cmd) {
+ ret = -1;
+ goto out;
+ }
- ret = dict_set_str (dict, CLIENT_CMD_CONNECT, dst_brick);
+ memcpy (clnt_cmd, data->data, data->len);
+ clnt_cmd[data->len] = '\0';
+ gf_log (this->name, GF_LOG_DEBUG, "Got destination brick %s\n",
+ clnt_cmd);
+
+ ret = dict_set_dynstr (dict, CLIENT_CMD_CONNECT, clnt_cmd);
if (ret < 0) {
gf_log (this->name, GF_LOG_ERROR,
"Could not inititiate destination brick "
@@ -942,8 +949,16 @@ pump_initiate_sink_connect (call_frame_t *frame, xlator_t *this)
ret = 0;
- dict_unref (dict);
out:
+ if (dict)
+ dict_unref (dict);
+
+ if (data)
+ data_unref (data);
+
+ if (ret && clnt_cmd)
+ GF_FREE (clnt_cmd);
+
return ret;
}
@@ -1067,10 +1082,12 @@ pump_execute_status (call_frame_t *frame, xlator_t *this)
dict = dict_new ();
- ret = dict_set_str (dict, PUMP_CMD_STATUS, dict_str);
+ ret = dict_set_dynstr (dict, PUMP_CMD_STATUS, dict_str);
if (ret < 0) {
gf_log (this->name, GF_LOG_DEBUG,
- "dict_set_str returned negative value");
+ "dict_set_dynstr returned negative value");
+ } else {
+ dict_str = NULL;
}
op_ret = 0;
@@ -1079,8 +1096,11 @@ out:
AFR_STACK_UNWIND (getxattr, frame, op_ret, op_errno, dict);
- dict_unref (dict);
- GF_FREE (dict_str);
+ if (dict)
+ dict_unref (dict);
+
+ if (dict_str)
+ GF_FREE (dict_str);
return 0;
}
@@ -2566,8 +2586,8 @@ init (xlator_t *this)
while (i < child_count) {
priv->children[i] = trav->xlator;
- ret = asprintf (&priv->pending_key[i], "%s.%s", AFR_XATTR_PREFIX,
- trav->xlator->name);
+ ret = gf_asprintf (&priv->pending_key[i], "%s.%s", AFR_XATTR_PREFIX,
+ trav->xlator->name);
if (-1 == ret) {
gf_log (this->name, GF_LOG_ERROR,
"asprintf failed to set pending key");