Skip to content

Fix dangling pointer glusterd_ac_send_friend_remove_req()#4653

Draft
ThalesBarretto wants to merge 2 commits intogluster:develfrom
ThalesBarretto:thales_leak_glusterd_ac_send_friend_remove
Draft

Fix dangling pointer glusterd_ac_send_friend_remove_req()#4653
ThalesBarretto wants to merge 2 commits intogluster:develfrom
ThalesBarretto:thales_leak_glusterd_ac_send_friend_remove

Conversation

@ThalesBarretto
Copy link
Contributor

@ThalesBarretto ThalesBarretto commented Feb 16, 2026

In glusterd-sm.c we always use use gf_strdup when assigning
the peername, preventing a potential crash or invalid memory access

But glusterd_ac_send_friend_remove_req() was inadvertely
assigning directly, without using strdup, causing a dangling pointer
problem which could potentially crash the application.

Since glusterd_ac_send_friend_remove_req() now uses gf_strdup()
to assign event->peername, the event destructor must free it.
Add GF_FREE(event->peername) to glusterd_destroy_friend_event_context()
which is the canonical cleanup path for all friend SM events.

Also call glusterd_destroy_friend_event_context() on the early-exit
path in glusterd_friend_sm() (peerinfo not found), which was calling
GF_FREE(event) directly and leaking the peername string.

The first commit fixes that problem by using the strdup() pattern
instead of the dangerous direct assignment.

The second address the memory leak introduced by the first, with a
consistend pattern.

@ThalesBarretto ThalesBarretto force-pushed the thales_leak_glusterd_ac_send_friend_remove branch from 12a34f7 to bad0e19 Compare February 16, 2026 01:07
@ThalesBarretto ThalesBarretto marked this pull request as ready for review February 16, 2026 01:13
pranithk
pranithk previously approved these changes Feb 16, 2026

if (!ret) {
new_event->peername = peerinfo->hostname;
new_event->peername = gf_strdup(peerinfo->hostname);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ThalesBarretto This change looks correct. It doesn't look like peername is getting freed in all scenarios though?

@sanjurakonde Could you also verify this when you get time. I am merging this PR

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually now that I check the code, some code is not doing free and some are. Which one is the correct way @sanjurakonde ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will wait for your response before merging.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pranithk @sanjurakonde i have introduced another commit to addres the leak, would you mind taking a look?

@ThalesBarretto ThalesBarretto marked this pull request as draft February 16, 2026 17:09
	In `glusterd-sm.c` we always use use gf_strdup when assigning
the peername, preventing a potential crash or invalid memory access

	But glusterd_ac_send_friend_remove_req() was inadvertely
assigning directly, without using `strdup`, causing a dangling
pointer problem which could potentially crash the application.

	This commit fixes that problem by using the `strdup()` pattern
instead of the dangerous direct assignment.
#  xlators/mgmt/glusterd/src/glusterd-sm.c | 2 +-
#  1 file changed, 1 insertion(+), 1 deletion(-)
@ThalesBarretto ThalesBarretto force-pushed the thales_leak_glusterd_ac_send_friend_remove branch from bad0e19 to 0154173 Compare February 18, 2026 11:20
        Since glusterd_ac_send_friend_remove_req() now uses gf_strdup()
   to assign event->peername, the event destructor must free it.
   Add GF_FREE(event->peername) to glusterd_destroy_friend_event_context()
   which is the canonical cleanup path for all friend SM events.

        Also call glusterd_destroy_friend_event_context() on the early-exit
   path in glusterd_friend_sm() (peerinfo not found), which was calling
   GF_FREE(event) directly and leaking the peername string.

Signed-off-by: Thales Antunes de Oliveira Barretto <thales.barretto.git@gmail.com>
#  xlators/mgmt/glusterd/src/glusterd-sm.c | 3 +++
#  1 file changed, 3 insertions(+)
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.

2 participants