From 77669043e290cb6a4c82dded96286370cf5c7db0 Mon Sep 17 00:00:00 2001 From: Sunny Kumar Date: Tue, 8 Jan 2019 16:35:35 +0530 Subject: afr : fix memory leak This patch fixes memory leak reported by ASan. The fix was first merged by https://review.gluster.org/#/c/glusterfs/+/21805. But later change was reverted due to this patch https://review.gluster.org/#/c/glusterfs/+/21178/. updates: bz#1633930 Change-Id: I1febe121e0be33a637397a0b54d6b78391692b0d Signed-off-by: Sunny Kumar --- xlators/cluster/afr/src/afr-common.c | 38 ++++++++++++++---------------------- 1 file changed, 15 insertions(+), 23 deletions(-) (limited to 'xlators/cluster/afr/src/afr-common.c') diff --git a/xlators/cluster/afr/src/afr-common.c b/xlators/cluster/afr/src/afr-common.c index 0f77607fee0..dceab865fab 100644 --- a/xlators/cluster/afr/src/afr-common.c +++ b/xlators/cluster/afr/src/afr-common.c @@ -6126,7 +6126,7 @@ out: } static dict_t * -afr_set_heal_info(char *status, const int status_len) +afr_set_heal_info(char *status) { dict_t *dict = NULL; int ret = -1; @@ -6137,8 +6137,7 @@ afr_set_heal_info(char *status, const int status_len) goto out; } - ret = dict_set_nstrn(dict, "heal-info", SLEN("heal-info"), status, - status_len); + ret = dict_set_dynstr_sizen(dict, "heal-info", status); if (ret) gf_msg("", GF_LOG_WARNING, -ret, AFR_MSG_DICT_SET_FAILED, "Failed to set heal-info key to " @@ -6170,7 +6169,6 @@ afr_get_heal_info(call_frame_t *frame, xlator_t *this, loc_t *loc) inode_t *inode = NULL; char *substr = NULL; char *status = NULL; - int status_len = 0; ret = afr_selfheal_locked_inspect(frame, this, loc->gfid, &inode, &entry_selfheal, &data_selfheal, @@ -6188,25 +6186,21 @@ afr_get_heal_info(call_frame_t *frame, xlator_t *this, loc_t *loc) } if (ret == -EIO) { - status_len = gf_asprintf(&status, "split-brain%s", - substr ? substr : ""); - if (status_len < 0) { - ret = status_len; + ret = gf_asprintf(&status, "split-brain%s", substr ? substr : ""); + if (ret < 0) { goto out; } - dict = afr_set_heal_info(status, status_len); + dict = afr_set_heal_info(status); if (!dict) { ret = -1; goto out; } } else if (ret == -EAGAIN) { - status_len = gf_asprintf(&status, "possibly-healing%s", - substr ? substr : ""); - if (status_len < 0) { - ret = status_len; + ret = gf_asprintf(&status, "possibly-healing%s", substr ? substr : ""); + if (ret < 0) { goto out; } - dict = afr_set_heal_info(status, status_len); + dict = afr_set_heal_info(status); if (!dict) { ret = -1; goto out; @@ -6222,18 +6216,17 @@ afr_get_heal_info(call_frame_t *frame, xlator_t *this, loc_t *loc) ret = -1; goto out; } - dict = afr_set_heal_info(status, strlen(status)); + dict = afr_set_heal_info(status); if (!dict) { ret = -1; goto out; } } else { - status_len = gf_asprintf(&status, "heal%s", substr ? substr : ""); - if (status_len < 0) { - ret = status_len; + ret = gf_asprintf(&status, "heal%s", substr ? substr : ""); + if (ret < 0) { goto out; } - dict = afr_set_heal_info(status, status_len); + dict = afr_set_heal_info(status); if (!dict) { ret = -1; goto out; @@ -6248,12 +6241,11 @@ afr_get_heal_info(call_frame_t *frame, xlator_t *this, loc_t *loc) * selfheal booleans is set. */ if (data_selfheal || entry_selfheal || metadata_selfheal) { - status_len = gf_asprintf(&status, "heal%s", substr ? substr : ""); - if (status_len < 0) { - ret = status_len; + ret = gf_asprintf(&status, "heal%s", substr ? substr : ""); + if (ret < 0) { goto out; } - dict = afr_set_heal_info(status, status_len); + dict = afr_set_heal_info(status); if (!dict) { ret = -1; goto out; -- cgit