fix: Resolve memory leak in stanza_parse by freeing parse state #2

Merged
jabber.developer2 merged 1 commits from fix/memory-leak-stanza-parse into master 2025-12-24 12:38:15 +00:00
Collaborator

Fix: Resolve memory leak in stanza_parse
Description
This PR fixes a memory leak in the stanza_parse function in stanza.c.

Problem
The ParseState structure allocated with malloc() was never freed, causing a memory leak on every call to stanza_parse().

Solution
Save the result pointer before freeing the parse state:

Changes
stanza.c: Store curr_stanza pointer in a local variable before freeing ParseState, then return the saved pointer.
Testing
The fix is safe because:

result holds a copy of the pointer value (memory address), not a reference to state
The XMPPStanza object pointed to by curr_stanza is allocated separately in stanza_new() and remains valid after free(state)
This is a standard pattern for returning data from temporary parsing structures
Impact
Eliminates memory leak of sizeof(ParseState) bytes per stanza_parse() call
No functional changes to the parsing behavior

Fix: Resolve memory leak in stanza_parse Description This PR fixes a memory leak in the stanza_parse function in stanza.c. Problem The ParseState structure allocated with malloc() was never freed, causing a memory leak on every call to stanza_parse(). Solution Save the result pointer before freeing the parse state: Changes stanza.c: Store curr_stanza pointer in a local variable before freeing ParseState, then return the saved pointer. Testing The fix is safe because: result holds a copy of the pointer value (memory address), not a reference to state The XMPPStanza object pointed to by curr_stanza is allocated separately in stanza_new() and remains valid after free(state) This is a standard pattern for returning data from temporary parsing structures Impact Eliminates memory leak of sizeof(ParseState) bytes per stanza_parse() call No functional changes to the parsing behavior
jabber.developer2 added 1 commit 2025-12-24 12:37:08 +00:00
jabber.developer2 merged commit 6faee6177d into master 2025-12-24 12:38:15 +00:00
jabber.developer2 deleted branch fix/memory-leak-stanza-parse 2025-12-24 12:38:16 +00:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: devs/stabber#2
No description provided.