summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2018-02-28 17:01:47 +0000
committerGitHub <noreply@github.com>2018-02-28 17:01:47 +0000
commite8e490b2765c45c3210d98b39ca0093c69cd24df (patch)
tree7ff977ddcacc14591c0a360a28b95ebc0a131cdc
parent17bef3b8363e1b6c12e8506b21715b00f82c3a82 (diff)
parent2022b00447a9edaa7caa712431c4888bbb1e0f67 (diff)
downloadlibgit2-e8e490b2765c45c3210d98b39ca0093c69cd24df.tar.gz
Merge pull request #4554 from pks-t/pks/curl-init
curl: initialize and cleanup global curl state
-rw-r--r--src/global.c6
-rw-r--r--src/streams/curl.c18
-rw-r--r--src/streams/curl.h1
3 files changed, 23 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;
diff --git a/src/streams/curl.c b/src/streams/curl.c
index 2f0610389..ee13be1dc 100644
--- a/src/streams/curl.c
+++ b/src/streams/curl.c
@@ -14,6 +14,7 @@
#include "stream.h"
#include "git2/transport.h"
#include "buffer.h"
+#include "global.h"
#include "vector.h"
#include "proxy.h"
@@ -38,6 +39,18 @@ typedef struct {
git_cred *proxy_cred;
} curl_stream;
+int git_curl_stream_global_init(void)
+{
+ if (curl_global_init(CURL_GLOBAL_ALL) != 0) {
+ giterr_set(GITERR_NET, "could not initialize curl");
+ return -1;
+ }
+
+ /* `curl_global_cleanup` is provided by libcurl */
+ git__on_shutdown(curl_global_cleanup);
+ return 0;
+}
+
static int seterr_curl(curl_stream *s)
{
giterr_set(GITERR_NET, "curl error: %s\n", s->curl_error);
@@ -353,6 +366,11 @@ int git_curl_stream_new(git_stream **out, const char *host, const char *port)
#include "stream.h"
+int git_curl_stream_global_init(void)
+{
+ return 0;
+}
+
int git_curl_stream_new(git_stream **out, const char *host, const char *port)
{
GIT_UNUSED(out);
diff --git a/src/streams/curl.h b/src/streams/curl.h
index 548feae2f..511cd894a 100644
--- a/src/streams/curl.h
+++ b/src/streams/curl.h
@@ -11,6 +11,7 @@
#include "git2/sys/stream.h"
+extern int git_curl_stream_global_init(void);
extern int git_curl_stream_new(git_stream **out, const char *host, const char *port);
#endif