Skip to content

Commit 2a09de9

Browse files
author
Edward Thomson
authored
Merge pull request libgit2#3816 from pks-t/pks/memory-leaks
Memory leak fixes
2 parents 65e4ab7 + 43c5511 commit 2a09de9

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-9
lines changed

src/global.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,6 @@ static void shutdown_common(void)
8787

8888
git__free(git__user_agent);
8989
git__free(git__ssl_ciphers);
90-
91-
#if defined(GIT_MSVC_CRTDBG)
92-
git_win32__crtdbg_stacktrace_cleanup();
93-
git_win32__stack_cleanup();
94-
#endif
9590
}
9691

9792
/**
@@ -183,6 +178,11 @@ int git_libgit2_shutdown(void)
183178

184179
TlsFree(_tls_index);
185180
git_mutex_free(&git__mwindow_mutex);
181+
182+
#if defined(GIT_MSVC_CRTDBG)
183+
git_win32__crtdbg_stacktrace_cleanup();
184+
git_win32__stack_cleanup();
185+
#endif
186186
}
187187

188188
/* Exit the lock */

src/transports/winhttp.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,11 +400,17 @@ static int winhttp_stream_connect(winhttp_stream *s)
400400
return -1;
401401
}
402402

403+
gitno_connection_data_free_ptrs(&t->proxy_connection_data);
404+
403405
if ((error = gitno_extract_url_parts(&t->proxy_connection_data.host, &t->proxy_connection_data.port, NULL,
404406
&t->proxy_connection_data.user, &t->proxy_connection_data.pass, proxy_url, NULL)) < 0)
405407
goto on_error;
406408

407409
if (t->proxy_connection_data.user && t->proxy_connection_data.pass) {
410+
if (t->proxy_cred) {
411+
t->proxy_cred->free(t->proxy_cred);
412+
}
413+
408414
if ((error = git_cred_userpass_plaintext_new(&t->proxy_cred, t->proxy_connection_data.user, t->proxy_connection_data.pass)) < 0)
409415
goto on_error;
410416
}
@@ -425,10 +431,11 @@ static int winhttp_stream_connect(winhttp_stream *s)
425431
}
426432

427433
/* Convert URL to wide characters */
428-
if ((error = git__utf8_to_16_alloc(&proxy_wide, processed_url.ptr)) < 0)
434+
error = git__utf8_to_16_alloc(&proxy_wide, processed_url.ptr);
435+
git_buf_free(&processed_url);
436+
if (error < 0)
429437
goto on_error;
430438

431-
432439
proxy_info.dwAccessType = WINHTTP_ACCESS_TYPE_NAMED_PROXY;
433440
proxy_info.lpszProxy = proxy_wide;
434441
proxy_info.lpszProxyBypass = NULL;
@@ -1481,12 +1488,19 @@ static int winhttp_close(git_smart_subtransport *subtransport)
14811488

14821489
gitno_connection_data_free_ptrs(&t->connection_data);
14831490
memset(&t->connection_data, 0x0, sizeof(gitno_connection_data));
1491+
gitno_connection_data_free_ptrs(&t->proxy_connection_data);
1492+
memset(&t->proxy_connection_data, 0x0, sizeof(gitno_connection_data));
14841493

14851494
if (t->cred) {
14861495
t->cred->free(t->cred);
14871496
t->cred = NULL;
14881497
}
14891498

1499+
if (t->proxy_cred) {
1500+
t->proxy_cred->free(t->proxy_cred);
1501+
t->proxy_cred = NULL;
1502+
}
1503+
14901504
if (t->url_cred) {
14911505
t->url_cred->free(t->url_cred);
14921506
t->url_cred = NULL;

tests/checkout/typechange.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,7 @@ static int make_submodule_dirty(git_submodule *sm, const char *name, void *paylo
240240
));
241241
git_futils_rmdir_r(git_buf_cstr(&submodulepath), NULL, GIT_RMDIR_REMOVE_FILES);
242242

243-
/* initialize submodule and its repository */
244-
cl_git_pass(git_submodule_init(sm, 1));
243+
/* initialize submodule's repository */
245244
cl_git_pass(git_submodule_repo_init(&submodule_repo, sm, 0));
246245

247246
/* create a file in the submodule workdir to make it dirty */
@@ -251,6 +250,7 @@ static int make_submodule_dirty(git_submodule *sm, const char *name, void *paylo
251250

252251
git_buf_free(&dirtypath);
253252
git_buf_free(&submodulepath);
253+
git_repository_free(submodule_repo);
254254

255255
return 0;
256256
}

0 commit comments

Comments
 (0)