Thanks to visit codestin.com
Credit goes to github.com

Skip to content

curl: initialize and cleanup global curl state #4554

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

Merged
merged 1 commit into from
Feb 28, 2018

Conversation

pks-t
Copy link
Member

@pks-t pks-t commented Feb 28, 2018

The documentation of curl states that any program making use of libcurl
is responsible for calling curl_global_init previous to using any
curl functions, and curl_global_cleanup when the program is about to
terminate. We currently call neither. While this seems to work just
fine, Valgrind may complain about unfree'd memory.

Fix the issue by correctly setting up and tearing down libcurl.


Edit for the corrected reasoning behind this PR:

Our curl-based streams make use of the easy curl interface. This
interface automatically initializes and de-initializes the global curl
state by calling out to curl_global_init and curl_global_cleanup.
Thus, all global state will be repeatedly re-initialized when creating
multiple curl streams in succession. Despite being inefficient, this is
not thread-safe due to curl_global_init being not thread-safe itself.
Thus a multi-threaded programing handling multiple curl streams at the
same time is inherently racy.

Fix the issue by globally initializing and cleaning up curl's state.

Our curl-based streams make use of the easy curl interface. This
interface automatically initializes and de-initializes the global curl
state by calling out to `curl_global_init` and `curl_global_cleanup`.
Thus, all global state will be repeatedly re-initialized when creating
multiple curl streams in succession. Despite being inefficient, this is
not thread-safe due to `curl_global_init` being not thread-safe itself.
Thus a multi-threaded programing handling multiple curl streams at the
same time is inherently racy.

Fix the issue by globally initializing and cleaning up curl's state.
@ethomson ethomson merged commit e8e490b into libgit2:master Feb 28, 2018
@pks-t pks-t deleted the pks/curl-init branch March 2, 2018 10:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants