mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-07 18:11:43 +00:00
Merge pull request #3051 from jeffhostetler/jeffhostetler/memleak_windows_tls_data
Attempt to fix Windows TLS memory leak.
This commit is contained in:
commit
aaf42c8df7
24
src/global.c
24
src/global.c
@ -223,13 +223,10 @@ int git_libgit2_init(void)
|
|||||||
|
|
||||||
static void synchronized_threads_shutdown(void)
|
static void synchronized_threads_shutdown(void)
|
||||||
{
|
{
|
||||||
void *ptr;
|
|
||||||
|
|
||||||
/* Shut down any subsystems that have global state */
|
/* Shut down any subsystems that have global state */
|
||||||
git__shutdown();
|
git__shutdown();
|
||||||
|
|
||||||
ptr = TlsGetValue(_tls_index);
|
git__free_tls_data();
|
||||||
git__global_state_cleanup(ptr);
|
|
||||||
|
|
||||||
TlsFree(_tls_index);
|
TlsFree(_tls_index);
|
||||||
git_mutex_free(&git__mwindow_mutex);
|
git_mutex_free(&git__mwindow_mutex);
|
||||||
@ -270,15 +267,20 @@ git_global_st *git__global_state(void)
|
|||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL WINAPI DllMain(HINSTANCE dll, DWORD reason, LPVOID reserved)
|
/**
|
||||||
|
* Free the TLS data associated with this thread.
|
||||||
|
* This should only be used by the thread as it
|
||||||
|
* is exiting.
|
||||||
|
*/
|
||||||
|
void git__free_tls_data(void)
|
||||||
{
|
{
|
||||||
if (reason == DLL_THREAD_DETACH) {
|
void *ptr = TlsGetValue(_tls_index);
|
||||||
void *ptr = TlsGetValue(_tls_index);
|
if (!ptr)
|
||||||
git__global_state_cleanup(ptr);
|
return;
|
||||||
git__free(ptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
return TRUE;
|
git__global_state_cleanup(ptr);
|
||||||
|
git__free(ptr);
|
||||||
|
TlsSetValue(_tls_index, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
#elif defined(GIT_THREADS) && defined(_POSIX_THREADS)
|
#elif defined(GIT_THREADS) && defined(_POSIX_THREADS)
|
||||||
|
@ -32,4 +32,6 @@ typedef void (*git_global_shutdown_fn)(void);
|
|||||||
|
|
||||||
extern void git__on_shutdown(git_global_shutdown_fn callback);
|
extern void git__on_shutdown(git_global_shutdown_fn callback);
|
||||||
|
|
||||||
|
extern void git__free_tls_data(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -20,6 +20,8 @@ static DWORD WINAPI git_win32__threadproc(LPVOID lpParameter)
|
|||||||
|
|
||||||
thread->result = thread->proc(thread->param);
|
thread->result = thread->proc(thread->param);
|
||||||
|
|
||||||
|
git__free_tls_data();
|
||||||
|
|
||||||
return CLEAN_THREAD_EXIT;
|
return CLEAN_THREAD_EXIT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user