[llvm] Fix thread handle leak on Windows (PR #156854)
Lukasz Mielicki via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 4 04:06:00 PDT 2025
https://github.com/lmielick created https://github.com/llvm/llvm-project/pull/156854
Contrary to pthread_join on Windows WaitForSingleObject does not destroy the thread handle. Add missing CloseHandle call to avoid a handle leak.
>From 2c1503de804ba2ef0d890dea0a70a7cf1e552430 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C5=81ukasz=20Mielicki?= <lukasz.mielicki at intel.com>
Date: Wed, 4 Jun 2025 11:55:12 +0200
Subject: [PATCH] Fix thread handle leak on Windows (#133)
---
llvm/lib/Support/Windows/Threading.inc | 3 +++
1 file changed, 3 insertions(+)
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) {
More information about the llvm-commits
mailing list