Skip to content

Fix allocator mismatch ech knownhosts - #21150

Closed
MarkLee131 wants to merge 4 commits into
curl:masterfrom
MarkLee131:fix-allocator-mismatch-ech-knownhosts
Closed

MarkLee131 wants to merge 4 commits into
curl:masterfrom
MarkLee131:fix-allocator-mismatch-ech-knownhosts

Conversation

@MarkLee131

Copy link
Copy Markdown
Contributor

Fix #21149

memory allocated by libcurl (curl_maprintf) must be freed with
curl_free(), and memory allocated by the tool (curlx_strdup via
findfile) must be freed with curlx_free().

- tool_cfgable: ech_config is allocated with curl_maprintf, free it
  with curl_free() instead of tool_safefree()
- config2setopts: known hosts from findfile() is allocated with
  curlx_strdup, free it with curlx_free() instead of curl_free()
- tool_findfile: fix comment to say curlx_free() instead of curl_free()

Follow-up to b71973c
Comment thread src/config2setopts.c Resolved
Comment thread src/tool_cfgable.c Resolved

@bagder bagder left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks! It needs some minor adjustments though

For knownhosts, curlx_strdup() the findfile() result so that
config->knownhosts always uses tool-memory.

For ech_config, curlx_strdup() the curl_maprintf() result so that
config->ech_config always uses tool-memory, matching the getstr() path.
@MarkLee131

Copy link
Copy Markdown
Contributor Author

Thanks for the review.
Updated: now using curlx_strdup() on both the findfile() result for knownhosts and the curl_maprintf() result for ech_config, so both pointers consistently use tool-memory throughout. Also reverted the findfile() comment and tool_cfgable.c back to tool_safefree accordingly.

@bagder bagder closed this in 9fcc7e4 Mar 30, 2026
@bagder

bagder commented Mar 30, 2026

Copy link
Copy Markdown
Member

Thanks!

outcast36 pushed a commit to greearb/curl that referenced this pull request Jun 3, 2026
memory allocated by libcurl (curl_maprintf) must be freed with
curl_free(), and memory allocated by the tool (curlx_strdup via
findfile) must be freed with curlx_free().

- tool_cfgable: ech_config is allocated with curl_maprintf, free it
  with curl_free() instead of tool_safefree()
- config2setopts: known hosts from findfile() is allocated with
  curlx_strdup, free it with curlx_free() instead of curl_free()

Follow-up to b71973c

Closes curl#21150
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

Two more allocator mismatches in the curl tool (same class as b71973c115)

2 participants