[Openmp-commits] [openmp] 92289bd - [Clang][OpenMP] Reapply "Memory leaks in OpenMP when affinity is disabled" (#226292) (#226294)
via Openmp-commits
openmp-commits at lists.llvm.org
Thu Sep 24 14:58:37 PDT 2026
Author: Thomas Köppe
Date: 2026-09-24T14:58:31-07:00
New Revision: 92289bdbced90ccc9f63da0c7fdaa71879c70964
URL: https://github.com/llvm/llvm-project/commit/92289bdbced90ccc9f63da0c7fdaa71879c70964
DIFF: https://github.com/llvm/llvm-project/commit/92289bdbced90ccc9f63da0c7fdaa71879c70964.diff
LOG: [Clang][OpenMP] Reapply "Memory leaks in OpenMP when affinity is disabled" (#226292) (#226294)
The previous version was applying a compiler flag to the smoke test
that would result in an unrunnable binary on non-ARM platforms. The
intention is for ASAN on ARM to run, and we get that by just not
specifying any flags and relying on the test system to include this
platform.
Added:
openmp/runtime/test/affinity/no_leak_with_disabled.c
Modified:
openmp/runtime/src/kmp_affinity.cpp
openmp/runtime/src/kmp_affinity.h
Removed:
################################################################################
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;
}
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);
diff --git a/openmp/runtime/test/affinity/no_leak_with_disabled.c b/openmp/runtime/test/affinity/no_leak_with_disabled.c
new file mode 100644
index 0000000000000..43a7f2692c3a3
--- /dev/null
+++ b/openmp/runtime/test/affinity/no_leak_with_disabled.c
@@ -0,0 +1,15 @@
+// RUN: %libomp-compile -fopenmp
+// RUN: %libomp-run
+// RUN: env KMP_AFFINITY=disabled %libomp-run
+
+// Check that no memory is leaked with KMP_AFFINITY=disabled.
+// The detection is done by ASAN/LSAN.
+
+#include <omp.h>
+
+int main(void) {
+#pragma omp parallel
+ {
+ omp_get_thread_num();
+ }
+}
More information about the Openmp-commits
mailing list