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

Comments

Projects
None yet
3 participants
@CrazyHackGUT
Contributor

CrazyHackGUT commented Sep 14, 2018

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

This comment has been minimized.

Member

danielgustafsson commented Sep 14, 2018

@danielgustafsson

This comment has been minimized.

Member

danielgustafsson commented Sep 14, 2018

@CrazyHackGUT

This comment has been minimized.

Contributor

CrazyHackGUT commented Sep 14, 2018

Ok, I create PR later.

@danielgustafsson

This comment has been minimized.

Member

danielgustafsson commented Sep 14, 2018

CrazyHackGUT added a commit to CrazyHackGUT/curl that referenced this issue Sep 15, 2018

Fix memory leak
See curl#2991 for more details

This was referenced Sep 15, 2018

@CrazyHackGUT

This comment has been minimized.

Contributor

CrazyHackGUT commented Sep 15, 2018

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

@bagder

This comment has been minimized.

Member

bagder commented Sep 18, 2018

Fixed in 23524bf

@bagder bagder closed this Sep 18, 2018

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