diff options
author | Sunny Kumar <sunkumar@redhat.com> | 2019-01-08 16:35:35 +0530 |
---|---|---|
committer | Pranith Kumar Karampuri <pkarampu@redhat.com> | 2019-01-11 02:56:37 +0000 |
commit | 77669043e290cb6a4c82dded96286370cf5c7db0 (patch) | |
tree | b8e9987e3623123854cb80a52a5b949942e85c18 /xlators/cluster | |
parent | f091c5570efd5c754c40d40336bad8183a3e16e0 (diff) |
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 <sunkumar@redhat.com>
Diffstat (limited to 'xlators/cluster')
-rw-r--r-- | xlators/cluster/afr/src/afr-common.c | 38 |
1 files changed, 15 insertions, 23 deletions
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; |