Skip to content

Fix leaks on realloc() failures - #3005

Closed
danielgustafsson wants to merge 2 commits into
curl:masterfrom
danielgustafsson:dg-realloc_memleaks
Closed

danielgustafsson wants to merge 2 commits into
curl:masterfrom
danielgustafsson:dg-realloc_memleaks

Conversation

@danielgustafsson

@danielgustafsson danielgustafsson commented Sep 17, 2018 •

Copy link
Copy Markdown
Contributor

Fix a few realloc() calls which overwrote the original pointer with the return value, causing a memory leak in case the reallocation failed.

This extends and replaces #2997 with additional fixes of the same kind in the examples as the one submitted there. The second commit fixes a memleak in darwinssl which was found by looking at this PR.

@CrazyHackGUT I've editorialized your commit a bit by fixing the other copy/paste realloc() issues in examples.

@CrazyHackGUT CrazyHackGUT mentioned this pull request Sep 17, 2018
Make sure to not overwrite the reallocated pointer in realloc() calls
to avoid a memleak on memory errors.
@CrazyHackGUT

Copy link
Copy Markdown
Contributor

👍

Comment thread lib/vtls/darwinssl.c Outdated

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.

Alternatively, use Curl_saferealloc there, which frees the memory on fail.

@danielgustafsson

danielgustafsson commented Sep 17, 2018 via email

Copy link
Copy Markdown
Contributor Author

The reallocation was using the input pointer for the return value, which
leads to a memory leak on reallication failure. Fix by instead use the
safe internal API call Curl_saferealloc().
@lock lock Bot locked as resolved and limited conversation to collaborators Dec 17, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants