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

Skip to content

Commit e8e490b

Browse files
authored
Merge pull request libgit2#4554 from pks-t/pks/curl-init
curl: initialize and cleanup global curl state
2 parents 17bef3b + 2022b00 commit e8e490b

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

src/global.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "sysdir.h"
1212
#include "filter.h"
1313
#include "merge_driver.h"
14+
#include "streams/curl.h"
1415
#include "streams/openssl.h"
1516
#include "thread-utils.h"
1617
#include "git2/global.h"
@@ -23,7 +24,7 @@
2324

2425
git_mutex git__mwindow_mutex;
2526

26-
#define MAX_SHUTDOWN_CB 9
27+
#define MAX_SHUTDOWN_CB 10
2728

2829
static git_global_shutdown_fn git__shutdown_callbacks[MAX_SHUTDOWN_CB];
2930
static git_atomic git__n_shutdown_callbacks;
@@ -63,7 +64,8 @@ static int init_common(void)
6364
(ret = git_filter_global_init()) == 0 &&
6465
(ret = git_merge_driver_global_init()) == 0 &&
6566
(ret = git_transport_ssh_global_init()) == 0 &&
66-
(ret = git_openssl_stream_global_init()) == 0)
67+
(ret = git_openssl_stream_global_init()) == 0 &&
68+
(ret = git_curl_stream_global_init()) == 0)
6769
ret = git_mwindow_global_init();
6870

6971
GIT_MEMORY_BARRIER;

src/streams/curl.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "stream.h"
1515
#include "git2/transport.h"
1616
#include "buffer.h"
17+
#include "global.h"
1718
#include "vector.h"
1819
#include "proxy.h"
1920

@@ -38,6 +39,18 @@ typedef struct {
3839
git_cred *proxy_cred;
3940
} curl_stream;
4041

42+
int git_curl_stream_global_init(void)
43+
{
44+
if (curl_global_init(CURL_GLOBAL_ALL) != 0) {
45+
giterr_set(GITERR_NET, "could not initialize curl");
46+
return -1;
47+
}
48+
49+
/* `curl_global_cleanup` is provided by libcurl */
50+
git__on_shutdown(curl_global_cleanup);
51+
return 0;
52+
}
53+
4154
static int seterr_curl(curl_stream *s)
4255
{
4356
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)
353366

354367
#include "stream.h"
355368

369+
int git_curl_stream_global_init(void)
370+
{
371+
return 0;
372+
}
373+
356374
int git_curl_stream_new(git_stream **out, const char *host, const char *port)
357375
{
358376
GIT_UNUSED(out);

src/streams/curl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include "git2/sys/stream.h"
1313

14+
extern int git_curl_stream_global_init(void);
1415
extern int git_curl_stream_new(git_stream **out, const char *host, const char *port);
1516

1617
#endif

0 commit comments

Comments
 (0)