[compiler-rt] [asan][win] Fix CreateThread leak (PR #126738)

via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 20 23:35:11 PST 2025


================
@@ -166,6 +190,15 @@ INTERCEPTOR_WINAPI(HANDLE, CreateThread, LPSECURITY_ATTRIBUTES security,
                             thr_flags, tid);
 }
 
+INTERCEPTOR_WINAPI(void, ExitThread, DWORD dwExitCode) {
+  DWORD key = atomic_load(&g_native_tls_key, memory_order_relaxed);
+  AsanThread *t = (AsanThread *)TlsGetValue(key);
----------------
GkvJwa wrote:

Of course there is another problem with the log
```
  CHECK(t->context());
  VReport(2, "SetCurrentThread: %p for thread %p\n", (void *)t->context(),
          (void *)GetThreadSelf());
  // Make sure we do not reset the current AsanThread.
  CHECK_EQ(0, AsanTSDGet());
---
// In contrast to POSIX, on Windows GetCurrentThreadId()
// returns a system-unique identifier.
tid_t GetTid() {
  return GetCurrentThreadId();
}

uptr GetThreadSelf() {
  return GetTid();
}
```
GetCurrentThreadId is returned a handle on Windows

https://github.com/llvm/llvm-project/pull/126738


More information about the llvm-commits mailing list