diff --git a/compiler-rt/lib/asan/asan_win.cpp b/compiler-rt/lib/asan/asan_win.cpp index 09a13b11cff1f..027340280e068 100644 --- a/compiler-rt/lib/asan/asan_win.cpp +++ b/compiler-rt/lib/asan/asan_win.cpp @@ -145,7 +145,6 @@ static thread_return_t THREAD_CALLING_CONV asan_thread_start(void *arg) { t->GetStartData(params); auto res = (*params.start_routine)(params.arg); - t->Destroy(); // POSIX calls this from TSD destructor. return res; } @@ -166,6 +165,13 @@ INTERCEPTOR_WINAPI(HANDLE, CreateThread, LPSECURITY_ATTRIBUTES security, thr_flags, tid); } +INTERCEPTOR_WINAPI(void, ExitThread, DWORD dwExitCode) { + AsanThread *t = (AsanThread *)__asan::GetCurrentThread(); + if (t) + t->Destroy(); + REAL(ExitThread)(dwExitCode); +} + // }}} namespace __asan { @@ -181,6 +187,7 @@ void InitializePlatformInterceptors() { (LPCWSTR)&InitializePlatformInterceptors, &pinned)); ASAN_INTERCEPT_FUNC(CreateThread); + ASAN_INTERCEPT_FUNC(ExitThread); ASAN_INTERCEPT_FUNC(SetUnhandledExceptionFilter); #ifdef _WIN64