summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPranith Kumar K <pranithk@gluster.com>2011-04-15 02:55:46 +0000
committerAnand Avati <avati@gluster.com>2011-04-15 03:58:47 -0700
commitb5d944f911f1638a8063235443410de36df6f2fd (patch)
tree579455ce7786fb015374eed4544a57f328b5d8df
parentb565cf8bfc75e6f6c85a47bc8a06737cd6e79fae (diff)
mgmt/glusterd: Memory leak and message cleanup
Signed-off-by: Pranith Kumar K <pranithk@gluster.com> Signed-off-by: Anand Avati <avati@gluster.com> BUG: 2764 (Cleanup memory leaks seen in quota and gsync code paths) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=2764
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-handler.c2
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-op-sm.c34
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-rpc-ops.c49
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-store.c2
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-utils.c5
5 files changed, 43 insertions, 49 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-handler.c b/xlators/mgmt/glusterd/src/glusterd-handler.c
index f4f2e0a2bef..42909136a8c 100644
--- a/xlators/mgmt/glusterd/src/glusterd-handler.c
+++ b/xlators/mgmt/glusterd/src/glusterd-handler.c
@@ -1874,6 +1874,8 @@ out:
if (!lock_fail)
(void) glusterd_opinfo_unlock ();
}
+ if (cli_req.volname)
+ free (cli_req.volname); //malloced by xdr
return ret;
}
diff --git a/xlators/mgmt/glusterd/src/glusterd-op-sm.c b/xlators/mgmt/glusterd/src/glusterd-op-sm.c
index 9719526a691..8f4b63096a0 100644
--- a/xlators/mgmt/glusterd/src/glusterd-op-sm.c
+++ b/xlators/mgmt/glusterd/src/glusterd-op-sm.c
@@ -924,7 +924,7 @@ glusterd_op_stage_replace_brick (dict_t *dict, char **op_errstr,
case GF_REPLACE_OP_ABORT:
if ((!glusterd_is_rb_paused (volinfo)) &&
(!glusterd_is_rb_started (volinfo))) {
- gf_log ("", GF_LOG_ERROR, "Replace brick is not "
+ gf_log ("", GF_LOG_ERROR, "Replace brick is not"
" started or paused for volume ");
ret = -1;
goto out;
@@ -1713,6 +1713,7 @@ volname_from_master (char *master)
return NULL;
return gf_strdup (master+1);
+
}
int
@@ -2441,7 +2442,7 @@ glusterd_verify_gsync_status_opts (dict_t *dict, char **op_errstr)
if ((ret) || (!exists)) {
gf_log ("", GF_LOG_WARNING, "volume name does not exist");
snprintf (errmsg, sizeof(errmsg), "Volume name %s does not"
- "exist", volname);
+ " exist", volname);
*op_errstr = gf_strdup (errmsg);
ret = -1;
goto out;
@@ -2462,6 +2463,8 @@ glusterd_verify_gsync_status_opts (dict_t *dict, char **op_errstr)
slave, op_errstr);
out:
+ if (volname)
+ GF_FREE (volname);
gf_log ("", GF_LOG_DEBUG, "Returning %d", ret);
return ret;
@@ -2542,7 +2545,7 @@ glusterd_op_stage_gsync_set (dict_t *dict, char **op_errstr)
if ((ret) || (!exists)) {
gf_log ("", GF_LOG_WARNING, "volume name does not exist");
snprintf (errmsg, sizeof(errmsg), "Volume name %s does not"
- "exist", volname);
+ " exist", volname);
*op_errstr = gf_strdup (errmsg);
ret = -1;
goto out;
@@ -4584,6 +4587,8 @@ glusterd_set_marker_gsync (char *master)
}
out:
+ if (volname)
+ GF_FREE (volname);
return ret;
}
@@ -4695,7 +4700,7 @@ glusterd_get_gsync_status (dict_t *dict, char **op_errstr, dict_t *rsp_dict)
if ((ret) || (!exists)) {
gf_log ("", GF_LOG_WARNING, "volume name does not exist");
snprintf (errmsg, sizeof(errmsg), "Volume name %s does not"
- "exist", volname);
+ " exist", volname);
*op_errstr = gf_strdup (errmsg);
ret = -1;
goto out;
@@ -4715,6 +4720,8 @@ glusterd_get_gsync_status (dict_t *dict, char **op_errstr, dict_t *rsp_dict)
slave, rsp_dict);
out:
+ if (volname)
+ GF_FREE (volname);
gf_log ("", GF_LOG_DEBUG, "Returning %d", ret);
return ret;
@@ -4826,6 +4833,8 @@ glusterd_op_gsync_set (dict_t *dict, char **op_errstr, dict_t *rsp_dict)
}
out:
+ if (volname)
+ GF_FREE (volname);
gf_log ("", GF_LOG_DEBUG,"Returning %d", ret);
return ret;
}
@@ -5160,7 +5169,6 @@ glusterd_quota_enable (glusterd_volinfo_t *volinfo, char **op_errstr,
gf_boolean_t *crawl)
{
int32_t ret = -1;
- char *status = NULL;
char *quota_status = NULL;
GF_VALIDATE_OR_GOTO ("glusterd", volinfo, out);
@@ -5189,12 +5197,6 @@ glusterd_quota_enable (glusterd_volinfo_t *volinfo, char **op_errstr,
*op_errstr = gf_strdup ("Enabling quota has been successful");
- status = gf_strdup ("on");
- if (status == NULL) {
- ret = -1;
- goto out;
- }
-
*crawl = _gf_true;
ret = 0;
@@ -5235,12 +5237,6 @@ glusterd_quota_disable (glusterd_volinfo_t *volinfo, char **op_errstr)
dict_del (volinfo->dict, VKEY_FEATURES_LIMIT_USAGE);
- quota_status = gf_strdup ("off");
- if (quota_status == NULL) {
- ret = -1;
- goto out;
- }
-
out:
return ret;
}
@@ -5318,8 +5314,8 @@ glusterd_quota_limit_usage (glusterd_volinfo_t *volinfo, dict_t *dict, char **op
quota_limits = value;
- ret = dict_set_str (volinfo->dict, VKEY_FEATURES_LIMIT_USAGE,
- quota_limits);
+ ret = dict_set_dynstr (volinfo->dict, VKEY_FEATURES_LIMIT_USAGE,
+ quota_limits);
if (ret) {
gf_log ("", GF_LOG_ERROR, "Unable to set quota limits" );
*op_errstr = gf_strdup ("failed to set limit");
diff --git a/xlators/mgmt/glusterd/src/glusterd-rpc-ops.c b/xlators/mgmt/glusterd/src/glusterd-rpc-ops.c
index 27fe5b5f8eb..3b5c3df6bd0 100644
--- a/xlators/mgmt/glusterd/src/glusterd-rpc-ops.c
+++ b/xlators/mgmt/glusterd/src/glusterd-rpc-ops.c
@@ -271,44 +271,40 @@ glusterd_op_send_cli_response (glusterd_op_t op, int32_t op_ret,
rsp.op_name = "";
rsp.master = "";
rsp.slave = "";
- rsp.glusterd_workdir = gf_strdup (conf->workdir);
- rsp.gsync_prefix = gf_strdup (GSYNCD_PREFIX);
+ rsp.glusterd_workdir = conf->workdir;
+ rsp.gsync_prefix = GSYNCD_PREFIX;
if (ctx) {
- ret = dict_get_str (ctx, "errstr",
- &str);
+ ret = dict_get_str (ctx, "errstr", &str);
if (ret == 0)
- rsp.op_errstr = gf_strdup (str);
- ret = dict_get_int32 (ctx, "type",
- &type);
+ rsp.op_errstr = str;
+ ret = dict_get_int32 (ctx, "type", &type);
if (ret == 0)
rsp.type = type;
ret = dict_get_int32 (ctx, "config_type",
&config_type);
if (ret == 0)
rsp.config_type = config_type;
- ret = dict_get_str (ctx, "master",
- &master);
+ ret = dict_get_str (ctx, "master", &master);
if (ret == 0)
- rsp.master = gf_strdup (master);
+ rsp.master = master;
- ret = dict_get_str (ctx, "slave",
- &slave);
+ ret = dict_get_str (ctx, "slave", &slave);
if (ret == 0)
- rsp.slave = gf_strdup (slave);
+ rsp.slave = slave;
- if (config_type ==
- GF_GSYNC_OPTION_TYPE_CONFIG_GET) {
- ret = dict_get_str (ctx, "op_name",
- &op_name);
+ if (config_type == GF_GSYNC_OPTION_TYPE_CONFIG_GET) {
+ ret = dict_get_str (ctx, "op_name", &op_name);
if (ret == 0)
- rsp.op_name =
- gf_strdup (op_name);
+ rsp.op_name = op_name;
}
ret = dict_allocate_and_serialize (ctx,
&rsp.status_dict.status_dict_val,
(size_t*)&rsp.status_dict.status_dict_len);
+ if (ret == 0)
+ free_ptr = rsp.status_dict.status_dict_val;
+
}
if (op_errstr)
rsp.op_errstr = op_errstr;
@@ -357,11 +353,11 @@ glusterd_op_send_cli_response (glusterd_op_t op, int32_t op_ret,
ctx = op_ctx;
if (op_errstr)
- rsp.op_errstr = gf_strdup (op_errstr);
+ rsp.op_errstr = op_errstr;
else {
ret = dict_get_str (ctx, "errstr", &errstr);
if (ret == 0)
- rsp.op_errstr = gf_strdup (errstr);
+ rsp.op_errstr = errstr;
else
rsp.op_errstr = "";
}
@@ -371,22 +367,19 @@ glusterd_op_send_cli_response (glusterd_op_t op, int32_t op_ret,
if (op_ret == 0 && ctx) {
ret = dict_get_str (ctx, "volname", &str);
if (ret == 0)
- rsp.volname = gf_strdup (str);
+ rsp.volname = str;
- ret = dict_get_int32
- (ctx, "type", &type);
+ ret = dict_get_int32 (ctx, "type", &type);
if (ret == 0)
rsp.type = type;
else
rsp.type = 0;
if (type == GF_QUOTA_OPTION_TYPE_LIST) {
- ret = dict_get_str
- (ctx,"limit_list", &str);
+ ret = dict_get_str (ctx,"limit_list", &str);
if (ret == 0)
- rsp.limit_list =
- gf_strdup (str);
+ rsp.limit_list = str;
}
}
cli_rsp = &rsp;
diff --git a/xlators/mgmt/glusterd/src/glusterd-store.c b/xlators/mgmt/glusterd/src/glusterd-store.c
index d31110156ef..9bbc2e618df 100644
--- a/xlators/mgmt/glusterd/src/glusterd-store.c
+++ b/xlators/mgmt/glusterd/src/glusterd-store.c
@@ -1516,7 +1516,7 @@ glusterd_store_retrieve_volume (char *volname)
gf_log ("", GF_LOG_WARNING,
"failed to parse uuid");
} else if (strstr (key, "slave")) {
- ret = dict_set_str(volinfo->gsync_slaves, key,
+ ret = dict_set_dynstr (volinfo->gsync_slaves, key,
gf_strdup (value));
if (ret) {
gf_log ("",GF_LOG_ERROR, "Error in "
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c
index 855215f65a5..97efb89ada4 100644
--- a/xlators/mgmt/glusterd/src/glusterd-utils.c
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.c
@@ -590,7 +590,10 @@ glusterd_volinfo_delete (glusterd_volinfo_t *volinfo)
ret = glusterd_volume_brickinfos_delete (volinfo);
if (ret)
goto out;
- dict_unref (volinfo->dict);
+ if (volinfo->dict)
+ dict_unref (volinfo->dict);
+ if (volinfo->gsync_slaves)
+ dict_unref (volinfo->gsync_slaves);
if (volinfo->logdir)
GF_FREE (volinfo->logdir);