Commit 8e851c1e8c8f92da41d44e15e0c75777e4d1110e

Edward Thomson 2015-03-03T16:41:59

libgit2_shutdown: free TLS data (win32) Free TLS data on thread exit (win32)

diff --git a/src/global.c b/src/global.c
index 2f31c7d..1f3432d 100644
--- a/src/global.c
+++ b/src/global.c
@@ -270,6 +270,17 @@ git_global_st *git__global_state(void)
 	return ptr;
 }
 
+BOOL WINAPI DllMain(HINSTANCE dll, DWORD reason, LPVOID reserved)
+{
+	if (reason == DLL_THREAD_DETACH) {
+		void *ptr = TlsGetValue(_tls_index);
+		git__global_state_cleanup(ptr);
+		git__free(ptr);
+	}
+
+	return TRUE;
+}
+
 #elif defined(GIT_THREADS) && defined(_POSIX_THREADS)
 
 static pthread_key_t _tls_key;