Skip to content

backport: "gluterd: fix memory leak in glusterd #4384 " #4466

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: release-11
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion xlators/mgmt/glusterd/src/glusterd-store.c
Original file line number Diff line number Diff line change
Expand Up @@ -2364,6 +2364,10 @@ glusterd_store_retrieve_snapd(glusterd_volinfo_t *volinfo)
SLEN(GLUSTERD_STORE_KEY_SNAPD_PORT))) {
volinfo->snapd.port = atoi(value);
}
GF_FREE(key);
GF_FREE(value);
key = NULL;
value = NULL;

ret = gf_store_iter_get_next(iter, &key, &value, &op_errno);
}
Expand Down Expand Up @@ -2896,6 +2900,10 @@ glusterd_store_retrieve_bricks(glusterd_volinfo_t *volinfo)
ret = 0;

out:
if (key)
GF_FREE(key);
if (value)
GF_FREE(value);
if (gf_store_iter_destroy(&tmpiter)) {
gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_STORE_ITER_DESTROY_FAIL,
"Failed to destroy store iter");
Expand Down Expand Up @@ -3041,6 +3049,10 @@ glusterd_store_retrieve_node_state(glusterd_volinfo_t *volinfo)

if (dup_value)
GF_FREE(dup_value);
if (key)
GF_FREE(key);
if (value)
GF_FREE(value);
if (ret) {
if (volinfo->rebal.dict)
dict_unref(volinfo->rebal.dict);
Expand Down Expand Up @@ -3283,7 +3295,7 @@ glusterd_store_update_volinfo(glusterd_volinfo_t *volinfo)
*/
if (!strcmp(key, "features.limit-usage"))
break;
ret = dict_set_str(volinfo->dict, key, gf_strdup(value));
ret = dict_set_dynstr(volinfo->dict, key, gf_strdup(value));
if (ret) {
gf_msg(this->name, GF_LOG_ERROR, 0,
GD_MSG_DICT_SET_FAILED,
Expand Down Expand Up @@ -4633,6 +4645,10 @@ glusterd_store_retrieve_peers(xlator_t *this)
peerinfo = glusterd_peerinfo_new(GD_FRIEND_STATE_DEFAULT, NULL, NULL,
0);
if (peerinfo == NULL) {
GF_FREE(key);
GF_FREE(value);
key = NULL;
value = NULL;
ret = -1;
goto next;
}
Expand Down
5 changes: 4 additions & 1 deletion xlators/mgmt/glusterd/src/glusterd-utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -7754,8 +7754,11 @@ glusterd_check_and_set_brick_xattr(char *host, char *path, uuid_t uuid,

ret = 0;
out:
if (strlen(msg))
if (strlen(msg)) {
if (*op_errstr)
GF_FREE(*op_errstr);
*op_errstr = gf_strdup(msg);
}

return ret;
}
Expand Down
6 changes: 5 additions & 1 deletion xlators/storage/posix/src/posix-helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -3288,6 +3288,8 @@ posix_cs_set_state(xlator_t *this, dict_t **rsp, gf_cs_obj_state state,
xattrsize = sys_fgetxattr(*fd, GF_CS_OBJECT_REMOTE, value,
xattrsize + 1);
if (xattrsize == -1) {
if (value)
GF_FREE(value);
gf_msg(this->name, GF_LOG_ERROR, 0, errno,
" getxattr failed for key %s", GF_CS_OBJECT_REMOTE);
goto out;
Expand All @@ -3311,6 +3313,8 @@ posix_cs_set_state(xlator_t *this, dict_t **rsp, gf_cs_obj_state state,
xattrsize = sys_lgetxattr(path, GF_CS_OBJECT_REMOTE, value,
xattrsize + 1);
if (xattrsize == -1) {
if (value)
GF_FREE(value);
gf_msg(this->name, GF_LOG_ERROR, 0, errno,
" getxattr failed for key %s", GF_CS_OBJECT_REMOTE);
goto out;
Expand All @@ -3325,7 +3329,7 @@ posix_cs_set_state(xlator_t *this, dict_t **rsp, gf_cs_obj_state state,
}

if (ret == 0) {
ret = dict_set_str_sizen(*rsp, GF_CS_OBJECT_REMOTE, value);
ret = dict_set_dynstr_sizen(*rsp, GF_CS_OBJECT_REMOTE, value);
if (ret) {
gf_msg(this->name, GF_LOG_ERROR, 0, 0,
"failed to set"
Expand Down