Skip to content

Commit d85fea7

Browse files
committed
[asan][win] Fix ExitThread leak
Intercept `ExitThread` and free the memory created by `VirtualAlloc'
1 parent dd59198 commit d85fea7

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

compiler-rt/lib/asan/asan_win.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@ static thread_return_t THREAD_CALLING_CONV asan_thread_start(void *arg) {
145145
t->GetStartData(params);
146146

147147
auto res = (*params.start_routine)(params.arg);
148-
t->Destroy(); // POSIX calls this from TSD destructor.
149148
return res;
150149
}
151150

@@ -166,6 +165,14 @@ INTERCEPTOR_WINAPI(HANDLE, CreateThread, LPSECURITY_ATTRIBUTES security,
166165
thr_flags, tid);
167166
}
168167

168+
INTERCEPTOR_WINAPI(void, ExitThread, DWORD dwExitCode) {
169+
AsanThread *t = (AsanThread *)__asan::GetCurrentThread();
170+
if (t) {
171+
t->Destroy();
172+
}
173+
REAL(ExitThread)(dwExitCode);
174+
}
175+
169176
// }}}
170177

171178
namespace __asan {
@@ -181,6 +188,7 @@ void InitializePlatformInterceptors() {
181188
(LPCWSTR)&InitializePlatformInterceptors, &pinned));
182189

183190
ASAN_INTERCEPT_FUNC(CreateThread);
191+
ASAN_INTERCEPT_FUNC(ExitThread);
184192
ASAN_INTERCEPT_FUNC(SetUnhandledExceptionFilter);
185193

186194
#ifdef _WIN64

0 commit comments

Comments
 (0)