From 292c60275e98c15fcbbc295b44c306d7b2ecb6af Mon Sep 17 00:00:00 2001 From: Patrick Steinhardt Date: Tue, 7 Jun 2016 12:29:16 +0200 Subject: tests: fix memory leaks in checkout::typechange --- tests/checkout/typechange.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/checkout/typechange.c b/tests/checkout/typechange.c index 1efea931a..8a5110caa 100644 --- a/tests/checkout/typechange.c +++ b/tests/checkout/typechange.c @@ -240,8 +240,7 @@ static int make_submodule_dirty(git_submodule *sm, const char *name, void *paylo )); git_futils_rmdir_r(git_buf_cstr(&submodulepath), NULL, GIT_RMDIR_REMOVE_FILES); - /* initialize submodule and its repository */ - cl_git_pass(git_submodule_init(sm, 1)); + /* initialize submodule's repository */ cl_git_pass(git_submodule_repo_init(&submodule_repo, sm, 0)); /* 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 git_buf_free(&dirtypath); git_buf_free(&submodulepath); + git_repository_free(submodule_repo); return 0; } -- cgit v1.2.1 From 432af52b37a10aec278bb322c6805967cca5fc49 Mon Sep 17 00:00:00 2001 From: Patrick Steinhardt Date: Tue, 7 Jun 2016 12:55:17 +0200 Subject: global: clean up crt only after freeing tls data The thread local storage is used to hold some global state that is dynamically allocated and should be freed upon exit. On Windows, we clean up the C run-time right after execution of registered shutdown callbacks and before cleaning up the TLS. When we clean up the CRT, we also cause it to analyze for memory leaks. As we did not free the TLS yet this will lead to false positives. Fix the issue by first freeing the TLS and cleaning up the CRT only afterwards. --- src/global.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/global.c b/src/global.c index e1836ee0f..32e497507 100644 --- a/src/global.c +++ b/src/global.c @@ -87,11 +87,6 @@ static void shutdown_common(void) git__free(git__user_agent); git__free(git__ssl_ciphers); - -#if defined(GIT_MSVC_CRTDBG) - git_win32__crtdbg_stacktrace_cleanup(); - git_win32__stack_cleanup(); -#endif } /** @@ -183,6 +178,11 @@ int git_libgit2_shutdown(void) TlsFree(_tls_index); git_mutex_free(&git__mwindow_mutex); + +#if defined(GIT_MSVC_CRTDBG) + git_win32__crtdbg_stacktrace_cleanup(); + git_win32__stack_cleanup(); +#endif } /* Exit the lock */ -- cgit v1.2.1 From 43c55111d9f313b4defd435335a50dda7933cf03 Mon Sep 17 00:00:00 2001 From: Patrick Steinhardt Date: Tue, 7 Jun 2016 14:14:07 +0200 Subject: winhttp: plug several memory leaks --- src/transports/winhttp.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/transports/winhttp.c b/src/transports/winhttp.c index 580c3b91b..78e42cf3b 100644 --- a/src/transports/winhttp.c +++ b/src/transports/winhttp.c @@ -400,11 +400,17 @@ static int winhttp_stream_connect(winhttp_stream *s) return -1; } + gitno_connection_data_free_ptrs(&t->proxy_connection_data); + if ((error = gitno_extract_url_parts(&t->proxy_connection_data.host, &t->proxy_connection_data.port, NULL, &t->proxy_connection_data.user, &t->proxy_connection_data.pass, proxy_url, NULL)) < 0) goto on_error; if (t->proxy_connection_data.user && t->proxy_connection_data.pass) { + if (t->proxy_cred) { + t->proxy_cred->free(t->proxy_cred); + } + if ((error = git_cred_userpass_plaintext_new(&t->proxy_cred, t->proxy_connection_data.user, t->proxy_connection_data.pass)) < 0) goto on_error; } @@ -425,10 +431,11 @@ static int winhttp_stream_connect(winhttp_stream *s) } /* Convert URL to wide characters */ - if ((error = git__utf8_to_16_alloc(&proxy_wide, processed_url.ptr)) < 0) + error = git__utf8_to_16_alloc(&proxy_wide, processed_url.ptr); + git_buf_free(&processed_url); + if (error < 0) goto on_error; - proxy_info.dwAccessType = WINHTTP_ACCESS_TYPE_NAMED_PROXY; proxy_info.lpszProxy = proxy_wide; proxy_info.lpszProxyBypass = NULL; @@ -1481,12 +1488,19 @@ static int winhttp_close(git_smart_subtransport *subtransport) gitno_connection_data_free_ptrs(&t->connection_data); memset(&t->connection_data, 0x0, sizeof(gitno_connection_data)); + gitno_connection_data_free_ptrs(&t->proxy_connection_data); + memset(&t->proxy_connection_data, 0x0, sizeof(gitno_connection_data)); if (t->cred) { t->cred->free(t->cred); t->cred = NULL; } + if (t->proxy_cred) { + t->proxy_cred->free(t->proxy_cred); + t->proxy_cred = NULL; + } + if (t->url_cred) { t->url_cred->free(t->url_cred); t->url_cred = NULL; -- cgit v1.2.1