[llvm] Fix thread handle leak on Windows (PR #156854)

via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 4 04:06:52 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-support

Author: Lukasz Mielicki (lmielick)

<details>
<summary>Changes</summary>

Contrary to pthread_join on Windows WaitForSingleObject does not destroy the thread handle. Add missing CloseHandle call to avoid a handle leak.

---
Full diff: https://github.com/llvm/llvm-project/pull/156854.diff


1 Files Affected:

- (modified) llvm/lib/Support/Windows/Threading.inc (+3) 


``````````diff
diff --git a/llvm/lib/Support/Windows/Threading.inc b/llvm/lib/Support/Windows/Threading.inc
index b11f216adeba4..fd872a2b133e9 100644
--- a/llvm/lib/Support/Windows/Threading.inc
+++ b/llvm/lib/Support/Windows/Threading.inc
@@ -42,6 +42,9 @@ void llvm_thread_join_impl(HANDLE hThread) {
   if (::WaitForSingleObject(hThread, INFINITE) == WAIT_FAILED) {
     ReportLastErrorFatal("WaitForSingleObject failed");
   }
+  if (::CloseHandle(hThread) == FALSE) {
+    ReportLastErrorFatal("CloseHandle failed");
+  }
 }
 
 void llvm_thread_detach_impl(HANDLE hThread) {

``````````

</details>


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


More information about the llvm-commits mailing list