diff options
author | Patrick Steinhardt <ps@pks.im> | 2018-02-28 12:06:59 +0000 |
---|---|---|
committer | Patrick Steinhardt <ps@pks.im> | 2018-02-28 13:27:07 +0000 |
commit | 2022b00447a9edaa7caa712431c4888bbb1e0f67 (patch) | |
tree | dfecd8c379dbe6696b3be77503e224fafe8b4629 /src/global.c | |
parent | c9d59c6140fc365eb7ab950fb1a33187a949d403 (diff) | |
download | libgit2-2022b00447a9edaa7caa712431c4888bbb1e0f67.tar.gz |
curl: explicitly initialize and cleanup global curl 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.
Diffstat (limited to 'src/global.c')
-rw-r--r-- | src/global.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/global.c b/src/global.c index 89183080b..2f9b45bcd 100644 --- a/src/global.c +++ b/src/global.c @@ -11,6 +11,7 @@ #include "sysdir.h" #include "filter.h" #include "merge_driver.h" +#include "streams/curl.h" #include "streams/openssl.h" #include "thread-utils.h" #include "git2/global.h" @@ -23,7 +24,7 @@ git_mutex git__mwindow_mutex; -#define MAX_SHUTDOWN_CB 9 +#define MAX_SHUTDOWN_CB 10 static git_global_shutdown_fn git__shutdown_callbacks[MAX_SHUTDOWN_CB]; static git_atomic git__n_shutdown_callbacks; @@ -63,7 +64,8 @@ static int init_common(void) (ret = git_filter_global_init()) == 0 && (ret = git_merge_driver_global_init()) == 0 && (ret = git_transport_ssh_global_init()) == 0 && - (ret = git_openssl_stream_global_init()) == 0) + (ret = git_openssl_stream_global_init()) == 0 && + (ret = git_curl_stream_global_init()) == 0) ret = git_mwindow_global_init(); GIT_MEMORY_BARRIER; |