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

[docs] Fix memory leak in example for CURLOPT_WRITE_FUNCTION #10390

Closed
wants to merge 3 commits into from

Conversation

Thomas1664
Copy link
Contributor

Fixes #10387

@@ -109,6 +109,9 @@ For all protocols

/* we pass our 'chunk' struct to the callback function */
curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *)&chunk);

/* remember to free the buffer */
free(chunk.response)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, at this point in the code this free() call will do no good since it hasn't had the chance to allocate anything yet!

Shouldn't you then also perhaps invoke curl_easy_perform() before the free is called?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I also fixed all remaining errors, i.e. curl_handle coming out of nowhere.

@bagder
Copy link
Member

bagder commented Feb 3, 2023

Thanks!

@bagder bagder closed this in c29ccb3 Feb 3, 2023
@Thomas1664 Thomas1664 deleted the fix-docs-leak branch February 3, 2023 10:51
bch pushed a commit to bch/curl that referenced this pull request Jul 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

CURLOPT_WRITEFUNCTION man page: Memory leak in example
2 participants