Skip to content

Commit 95a2966

Browse files
authored
Merge pull request libgit2#5908 from punkymaniac/patch-mem-leak
Fix memory leak in git_smart__connect
2 parents 6be9e80 + bea1b02 commit 95a2966

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

src/transports/smart.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,8 @@ static int git_smart__connect(
226226
t->url = git__strdup(url);
227227
GIT_ERROR_CHECK_ALLOC(t->url);
228228

229+
git_proxy_options_clear(&t->proxy);
230+
229231
if (git_proxy_options_dup(&t->proxy, proxy) < 0)
230232
return -1;
231233

tests/online/fetch.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,19 @@
33
static git_repository *_repo;
44
static int counter;
55

6+
static char *_remote_proxy_scheme = NULL;
7+
static char *_remote_proxy_host = NULL;
8+
static char *_remote_proxy_user = NULL;
9+
static char *_remote_proxy_pass = NULL;
10+
611
void test_online_fetch__initialize(void)
712
{
813
cl_git_pass(git_repository_init(&_repo, "./fetch", 0));
14+
15+
_remote_proxy_scheme = cl_getenv("GITTEST_REMOTE_PROXY_SCHEME");
16+
_remote_proxy_host = cl_getenv("GITTEST_REMOTE_PROXY_HOST");
17+
_remote_proxy_user = cl_getenv("GITTEST_REMOTE_PROXY_USER");
18+
_remote_proxy_pass = cl_getenv("GITTEST_REMOTE_PROXY_PASS");
919
}
1020

1121
void test_online_fetch__cleanup(void)
@@ -14,6 +24,11 @@ void test_online_fetch__cleanup(void)
1424
_repo = NULL;
1525

1626
cl_fixture_cleanup("./fetch");
27+
28+
git__free(_remote_proxy_scheme);
29+
git__free(_remote_proxy_host);
30+
git__free(_remote_proxy_user);
31+
git__free(_remote_proxy_pass);
1732
}
1833

1934
static int update_tips(const char *refname, const git_oid *a, const git_oid *b, void *data)
@@ -207,3 +222,28 @@ void test_online_fetch__twice(void)
207222

208223
git_remote_free(remote);
209224
}
225+
226+
void test_online_fetch__proxy(void)
227+
{
228+
git_remote *remote;
229+
git_buf url = GIT_BUF_INIT;
230+
git_fetch_options fetch_opts;
231+
232+
if (!_remote_proxy_host || !_remote_proxy_user || !_remote_proxy_pass)
233+
cl_skip();
234+
235+
cl_git_pass(git_buf_printf(&url, "%s://%s:%s@%s/",
236+
_remote_proxy_scheme ? _remote_proxy_scheme : "http",
237+
_remote_proxy_user, _remote_proxy_pass, _remote_proxy_host));
238+
239+
cl_git_pass(git_fetch_options_init(&fetch_opts, GIT_FETCH_OPTIONS_VERSION));
240+
fetch_opts.proxy_opts.type = GIT_PROXY_SPECIFIED;
241+
fetch_opts.proxy_opts.url = url.ptr;
242+
243+
cl_git_pass(git_remote_create(&remote, _repo, "test", "https://github.com/libgit2/TestGitRepository.git"));
244+
cl_git_pass(git_remote_connect(remote, GIT_DIRECTION_FETCH, NULL, &fetch_opts.proxy_opts, NULL));
245+
cl_git_pass(git_remote_fetch(remote, NULL, &fetch_opts, NULL));
246+
247+
git_remote_free(remote);
248+
git_buf_dispose(&url);
249+
}

0 commit comments

Comments
 (0)