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

Conversation

ThalesBarretto
Copy link
Contributor

This is a trivial backport of "gluterd: fix memory leak in glusterd #4384"

The main reason for backport is to fix xlators/storage/posix/src/posix-helpers.c by
plugging memory leaks in posix_cs_set_state(), which are critical in certain environments.

Backport this so packagers can pick this fix until the release for v12 comes.

@gluster-ant
Copy link
Collaborator

Can one of the admins verify this patch?

1 similar comment
@gluster-ant
Copy link
Collaborator

Can one of the admins verify this patch?

@gluster-ant
Copy link
Collaborator

CLANG-FORMAT FAILURE:
Before merging the patch, this diff needs to be considered for passing clang-format

index e3c02893d..ce3d7a439 100644
--- a/xlators/mgmt/glusterd/src/glusterd-store.c
+++ b/xlators/mgmt/glusterd/src/glusterd-store.c
@@ -2364,10 +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;
+        GF_FREE(key);
+        GF_FREE(value);
+        key = NULL;
+        value = NULL;
 
         ret = gf_store_iter_get_next(iter, &key, &value, &op_errno);
     }
@@ -2900,10 +2900,10 @@ glusterd_store_retrieve_bricks(glusterd_volinfo_t *volinfo)
     ret = 0;
 
 out:
-	if (key)
-			GF_FREE(key);
-	if (value)
-			GF_FREE(value);
+    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");
@@ -3049,10 +3049,10 @@ out:
 
     if (dup_value)
         GF_FREE(dup_value);
-	if (key)
-		GF_FREE(key);
-	if (value)
-		GF_FREE(value);
+    if (key)
+        GF_FREE(key);
+    if (value)
+        GF_FREE(value);
     if (ret) {
         if (volinfo->rebal.dict)
             dict_unref(volinfo->rebal.dict);
@@ -4645,10 +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;
+            GF_FREE(key);
+            GF_FREE(value);
+            key = NULL;
+            value = NULL;
             ret = -1;
             goto next;
         }
diff --git a/xlators/storage/posix/src/posix-helpers.c b/xlators/storage/posix/src/posix-helpers.c
index 7fc4058e6..df3ed735a 100644
--- a/xlators/storage/posix/src/posix-helpers.c
+++ b/xlators/storage/posix/src/posix-helpers.c
@@ -3288,8 +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);
+                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;
@@ -3313,8 +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);
+                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;

@ThalesBarretto
Copy link
Contributor Author

@mohit84 do u mind reviewing this one? thanks in advance

mohit84
mohit84 previously approved these changes Feb 3, 2025
@mohit84
Copy link
Contributor

mohit84 commented Feb 3, 2025

/run regression

@mohit84 mohit84 requested a review from pranithk February 3, 2025 02:30
	Backport of 599c608 in branch devel.

	This part fixes two leaks in posix_cs_set_state.

	The first is due to the lack of GF_FREE(value) at two paths.
	The second is due to innapropriate use of dict_set_str_sizen().

Reported-by: chenjinhao <[email protected]>
Signed-off-by: Thales Antunes de Oliveira Barretto <[email protected]>
	refers to "* glusterd: fix memory leaks due to lack of GF_FREE"

	This part fixes leaks in glusterd-stored.c and glusterd-utils.c.

	In the first file it changes at glusterd_store_retrieve_snapd,
glusterd_store_retrieve_bricks, glusterd_store_update_volinfo, and
glusterd_store_retrieve_peers.  In the second file it changes just
glusterd_check_and_set_brick_xattr.

	In glusterd-store.c, there are while loops in gf_store_iter_get_next
and also in glusterd_store_retrieve_peers when reaching 'out' there will be
memory leak. The memory for 'key' and 'value' will be leaked once
gf_store_iter_get_next is called again next loop.

	In glusterd-utils.c, glusterd_is_path_in_use will be called
during volume creation to check brick path reuse. Under normal circumnstances, there is no problem. However, when a `force` cmd is given during volume
creation and the futher sys_lsetxattr failed, the memory area previously
pointed by *op_errstr will be leaked.

Reported-by: chenjinhao <[email protected]>
Signed-off-by: Thales Antunes de Oliveira Barretto <[email protected]>
@ThalesBarretto
Copy link
Contributor Author

I did just some formatting to pass clang format, and improved the commit messages.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants