fix: Resolve memory leak in stanza_parse by freeing parse state #2
Reference in New Issue
Block a user
No description provided.
Delete Branch "fix/memory-leak-stanza-parse"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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