Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a1cf264

Browse files
carlosmnEdward Thomson
authored and
Edward Thomson
committed
win32: free thread-local data on thread exit
1 parent e97d2d7 commit a1cf264

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/global.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,20 @@ void git__free_tls_data(void)
224224
TlsSetValue(_tls_index, NULL);
225225
}
226226

227+
BOOL WINAPI DllMain(HINSTANCE hInstDll, DWORD fdwReason, LPVOID lpvReserved)
228+
{
229+
/* This is how Windows lets us know our thread is being shut down */
230+
if (fdwReason == DLL_THREAD_DETACH) {
231+
git__free_tls_data();
232+
}
233+
234+
/*
235+
* Windows pays attention to this during library loading. We don't do anything
236+
* so we trivially succeed.
237+
*/
238+
return TRUE;
239+
}
240+
227241
#elif defined(GIT_THREADS) && defined(_POSIX_THREADS)
228242

229243
static pthread_key_t _tls_key;

0 commit comments

Comments
 (0)