Fix leaks on realloc() failures#3005
Closed
danielgustafsson wants to merge 2 commits intocurl:masterfrom
Closed
Conversation
Closed
Make sure to not overwrite the reallocated pointer in realloc() calls to avoid a memleak on memory errors.
9f7bd83 to
3f26864
Compare
Contributor
|
👍 |
bagder
approved these changes
Sep 17, 2018
Member
There was a problem hiding this comment.
Alternatively, use Curl_saferealloc there, which frees the memory on fail.
3f26864 to
e56082f
Compare
Member
Author
|
On 17 Sep 2018, at 19:40, Daniel Stenberg ***@***.***> wrote:
Alternatively, use Curl_saferealloc there, which frees the memory on fail.
That’s a good point, I prefer that over a plain realloc call here. Pushed another rebase with that instead.
|
nickzman
approved these changes
Sep 17, 2018
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().
e56082f to
f828ef1
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.