-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
Labels
Comments
On 14 Sep 2018, at 10:28, Kruzya ***@***.***> wrote:
https://github.com/curl/curl/blob/5bd8c389a3625e5c3eed265942d4c5b1e7e5d117/docs/examples/getinmemory.c#L45-L50
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.
This is not actually a memory leak as the input pointer isn’t left dangling. The pointer which wasn’t reallocated will subsequently be freed as the main function exits (line 109) unless I’m misreading this.
|
On 14 Sep 2018, at 10:34, Daniel Gustafsson ***@***.***> wrote:
> On 14 Sep 2018, at 10:28, Kruzya ***@***.***> wrote:
>
> https://github.com/curl/curl/blob/5bd8c389a3625e5c3eed265942d4c5b1e7e5d117/docs/examples/getinmemory.c#L45-L50
> 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.
This is not actually a memory leak as the input pointer isn’t left dangling. The pointer which wasn’t reallocated will subsequently be freed as the main function exits (line 109) unless I’m misreading this.
No, I’m wrong and you’re right (as @bagder pointed out on IRC), that is indeed a leak. Do you wan’t to submit a PR with a fix for this example?
|
Ok, I create PR later. |
On 14 Sep 2018, at 23:31, Kruzya ***@***.***> wrote:
Ok, I create PR later.
Thanks!
|
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
Closed
I missed one time and created pull also in my fork 🤣 |
Fixed in 23524bf |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
curl/docs/examples/getinmemory.c
Lines 45 to 50 in 5bd8c38
realloc
can returnnull
if he can't extend the memory. This case here envisaged, but...realloc
doesn't clean memory. We got a memory leak ifrealloc
returnnull
.If we open
realloc
documentation, we can see:The text was updated successfully, but these errors were encountered: