New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix leaks on realloc() failures #3005
Closed
danielgustafsson
wants to merge
2
commits into
curl:master
from
danielgustafsson:dg-realloc_memleaks
Closed
Fix leaks on realloc() failures #3005
danielgustafsson
wants to merge
2
commits into
curl:master
from
danielgustafsson:dg-realloc_memleaks
Conversation
This file contains 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
Closed
Make sure to not overwrite the reallocated pointer in realloc() calls to avoid a memleak on memory errors.
9f7bd83
to
3f26864
Compare
|
bagder
approved these changes
Sep 17, 2018
lib/vtls/darwinssl.c
Outdated
@@ -2056,11 +2056,14 @@ static int read_cert(const char *file, unsigned char **out, size_t *outlen) | |||
|
|||
if(len + n >= cap) { | |||
cap *= 2; | |||
data = realloc(data, cap); | |||
if(!data) { | |||
ptr = realloc(data, cap); |
There was a problem hiding this comment.
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.
3f26864
to
e56082f
Compare
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
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.
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.