Skip to content

Freeqpairs, fixing memry leak for trimmed/replaced query pairs - #437

Merged
bagder merged 1 commit into
curl:masterfrom
arpitguptagithub:fix/freeqpairs-memory-leak
Apr 12, 2026
Merged

Freeqpairs, fixing memry leak for trimmed/replaced query pairs#437
bagder merged 1 commit into
curl:masterfrom
arpitguptagithub:fix/freeqpairs-memory-leak

Conversation

@arpitguptagithub

Copy link
Copy Markdown

When trim() or replace() marks a query pair as deleted, they set len = 0 but allocate a new str via xstrdup(""). Since freeqpairs() only freed entries where len != 0, those strdup'd empty strings were leaked.

The fix is quite easy just check str (non-NULL) instead of len (non-zero) as the guard for freeing.

Add a test that trims a middle query key to exercise this code path.

@arpitguptagithub
arpitguptagithub force-pushed the fix/freeqpairs-memory-leak branch from 8fe3e97 to 62d105e Compare April 11, 2026 09:11
When trim() or replace() marks a query pair as deleted, they set
len = 0 but allocate a new str via xstrdup(""). Since freeqpairs()
only freed entries where len != 0, those strdup'd empty strings were
leaked.

Fix by checking str (non-NULL) instead of len (non-zero) as the guard
for freeing.

Add a test that trims a middle query key to exercise this code path.
@arpitguptagithub
arpitguptagithub force-pushed the fix/freeqpairs-memory-leak branch from 62d105e to 7acd826 Compare April 11, 2026 09:17
@bagder
bagder merged commit 5e7d624 into curl:master Apr 12, 2026
13 checks passed
@bagder

bagder commented Apr 12, 2026

Copy link
Copy Markdown
Member

Thanks!

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