Skip to content
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

Potential memory leak in getinmemory.c example #2991

Closed
CrazyHackGUT opened this issue Sep 14, 2018 · 6 comments
Closed

Potential memory leak in getinmemory.c example #2991

CrazyHackGUT opened this issue Sep 14, 2018 · 6 comments

Comments

@CrazyHackGUT
Copy link
Contributor

mem->memory = realloc(mem->memory, mem->size + realsize + 1);
if(mem->memory == NULL) {
/* out of memory! */
printf("not enough memory (realloc returned NULL)\n");
return 0;
}

realloc can return null if he can't extend the memory. This case here envisaged, but...
realloc doesn't clean memory. We got a memory leak if realloc return null.

If we open realloc documentation, we can see:

A null-pointer indicates that the function failed to allocate storage, and thus the block pointed by ptr was not modified.
@danielgustafsson
Copy link
Member

danielgustafsson commented Sep 14, 2018 via email

@danielgustafsson
Copy link
Member

danielgustafsson commented Sep 14, 2018 via email

@CrazyHackGUT
Copy link
Contributor Author

Ok, I create PR later.

@danielgustafsson
Copy link
Member

danielgustafsson commented Sep 14, 2018 via email

CrazyHackGUT added a commit to CrazyHackGUT/curl that referenced this issue Sep 15, 2018
See curl#2991 for more details
This was referenced Sep 15, 2018
@CrazyHackGUT
Copy link
Contributor Author

I missed one time and created pull also in my fork 🤣
Just ignore him in this issue.

@bagder
Copy link
Member

bagder commented Sep 18, 2018

Fixed in 23524bf

@bagder bagder closed this as completed Sep 18, 2018
@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.
Development

No branches or pull requests

3 participants