[Openmp-commits] [openmp] Memory leaks in OpenMP when affinity is disabled (PR #225441)
Thomas Köppe via Openmp-commits
openmp-commits at lists.llvm.org
Tue Sep 22 10:56:10 PDT 2026
https://github.com/tkoeppe updated https://github.com/llvm/llvm-project/pull/225441
>From bb6060fd2245092abcda6a4f7aad8207c3c29c4f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Thomas=20K=C3=B6ppe?= <tkoeppe at google.com>
Date: Tue, 22 Sep 2026 16:48:44 +0100
Subject: [PATCH 1/2] [Clang][OpenMP] Don't call __kmp_allocate with zero
argument.
Found by the ASAN leak sanitizer.
---
openmp/runtime/src/kmp_affinity.h | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/openmp/runtime/src/kmp_affinity.h b/openmp/runtime/src/kmp_affinity.h
index fa69585f7e2d5..97b40fe360b6d 100644
--- a/openmp/runtime/src/kmp_affinity.h
+++ b/openmp/runtime/src/kmp_affinity.h
@@ -350,7 +350,10 @@ class KMPNativeAffinity : public KMPAffinity {
public:
mask_t *mask;
- Mask() { mask = (mask_t *)__kmp_allocate(__kmp_affin_mask_size); }
+ Mask()
+ : mask(__kmp_affin_mask_size == 0
+ ? nullptr
+ : (mask_t *)__kmp_allocate(__kmp_affin_mask_size)) {}
~Mask() {
if (mask)
__kmp_free(mask);
>From 8324c9ca2b754b3222511ce51dc65735e988a6da Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Thomas=20K=C3=B6ppe?= <tkoeppe at google.com>
Date: Tue, 22 Sep 2026 16:53:40 +0100
Subject: [PATCH 2/2] [Clang][OpenMP] Missing cleanup before early return in
__kmp_affinity_create_cpuinfo_map
Found by the ASAN leak sanitizer.
---
openmp/runtime/src/kmp_affinity.cpp | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/openmp/runtime/src/kmp_affinity.cpp b/openmp/runtime/src/kmp_affinity.cpp
index 6a0e2910db8e0..31fe46be82cc2 100644
--- a/openmp/runtime/src/kmp_affinity.cpp
+++ b/openmp/runtime/src/kmp_affinity.cpp
@@ -3798,6 +3798,11 @@ static bool __kmp_affinity_create_cpuinfo_map(int *line,
__kmp_ncores = totals[coreIdIndex];
if (!KMP_AFFINITY_CAPABLE()) {
KMP_ASSERT(__kmp_affinity.type == affinity_none);
+ __kmp_free(lastId);
+ __kmp_free(totals);
+ __kmp_free(maxCt);
+ __kmp_free(counts);
+ CLEANUP_THREAD_INFO;
return true;
}
More information about the Openmp-commits
mailing list