Skip to content

Fix memory leak and dead code in get_structure_callback#54

Open
iliaal wants to merge 1 commit into
php:masterfrom
iliaal:pr/structure-callback-smartstring
Open

Fix memory leak and dead code in get_structure_callback#54
iliaal wants to merge 1 commit into
php:masterfrom
iliaal:pr/structure-callback-smartstring

Conversation

@iliaal
Copy link
Copy Markdown

@iliaal iliaal commented Jun 7, 2026

get_structure_callback emalloc'd a fixed 1KB buffer per part and, on the "too many sections" path, returned FAILURE without freeing it. The grow-and-bail block was also dead code: erealloc aborts rather than returning NULL, and the size check could only fire after the doubling realloc had already grown the buffer.

Replaced the manual buffer with a smart_string that grows on demand and is always freed. The output (dot-joined section ids) is unchanged.

The callback emalloc'd a fixed 1KB buffer for every part and, on the
"too many sections" path, returned FAILURE without freeing it. That
grow-and-bail logic was also dead code: erealloc aborts rather than
returning NULL, and the size check could only fire after the doubling
realloc had already grown the buffer.

Replace the manual buffer with a smart_string that grows as needed and
is always released. The output (dot-joined section ids) is unchanged.
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.

1 participant