[compiler-rt] [compiler-rt] Destroy pthread attrs after use in tests (PR #114923)
Kyle Evans via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 4 20:16:14 PST 2024
https://github.com/kevans91 created https://github.com/llvm/llvm-project/pull/114923
The attr typically located on the stack is of an opaque pthread_attr_t type, which may be a pointer that gets initialized by pthread_attr_init(). Explicitly clean up the attr with pthread_attr_destroy() to avoid a leak on such platforms to avoid unexpected test failures with lsan enabled.
This primarily affects FreeBSD; NetBSD, musl, and glibc will seemingly all use a full-sized pthread_attr_t.
>From 076ae350f0a1395d7bac4a3e2e81aa8d5241b931 Mon Sep 17 00:00:00 2001
From: Kyle Evans <kevans at FreeBSD.org>
Date: Mon, 4 Nov 2024 21:14:40 -0600
Subject: [PATCH] [compiler-rt] Destroy pthread attrs after use in tests
The attr typically located on the stack is of an opaque pthread_attr_t
type, which may be a pointer that gets initialized by pthread_attr_init().
Explicitly clean up the attr with pthread_attr_destroy() to avoid a leak on
such platforms to avoid unexpected test failures with lsan enabled.
This primarily affects FreeBSD; NetBSD, musl, and glibc will seemingly all
use a full-sized pthread_attr_t.
---
compiler-rt/test/asan/TestCases/Posix/fake_stack_gc.cpp | 1 +
.../test/asan/TestCases/Posix/unpoison-alternate-stack.cpp | 1 +
.../test/lsan/TestCases/leak_check_before_thread_started.cpp | 1 +
3 files changed, 3 insertions(+)
diff --git a/compiler-rt/test/asan/TestCases/Posix/fake_stack_gc.cpp b/compiler-rt/test/asan/TestCases/Posix/fake_stack_gc.cpp
index 8c368b9b1b947f..36fdf81120b59d 100644
--- a/compiler-rt/test/asan/TestCases/Posix/fake_stack_gc.cpp
+++ b/compiler-rt/test/asan/TestCases/Posix/fake_stack_gc.cpp
@@ -89,6 +89,7 @@ int main(void) {
pthread_t tid;
assert(pthread_create(&tid, &attr, Thread, alt_stack) == 0);
+ assert(pthread_attr_destroy(&attr) == 0);
pthread_join(tid, nullptr);
diff --git a/compiler-rt/test/asan/TestCases/Posix/unpoison-alternate-stack.cpp b/compiler-rt/test/asan/TestCases/Posix/unpoison-alternate-stack.cpp
index 593114bdf2e8df..8e7d5082d0b5d9 100644
--- a/compiler-rt/test/asan/TestCases/Posix/unpoison-alternate-stack.cpp
+++ b/compiler-rt/test/asan/TestCases/Posix/unpoison-alternate-stack.cpp
@@ -159,6 +159,7 @@ int main() {
pthread_attr_init(&ThreadAttr);
pthread_attr_setstack(&ThreadAttr, Mapping, DefaultStackSize);
pthread_create(&Thread, &ThreadAttr, &threadFun, (void *)&AltStack);
+ pthread_attr_destroy(&ThreadAttr);
pthread_join(Thread, nullptr);
diff --git a/compiler-rt/test/lsan/TestCases/leak_check_before_thread_started.cpp b/compiler-rt/test/lsan/TestCases/leak_check_before_thread_started.cpp
index 68eea93a81e57e..d0363a0bf85aeb 100644
--- a/compiler-rt/test/lsan/TestCases/leak_check_before_thread_started.cpp
+++ b/compiler-rt/test/lsan/TestCases/leak_check_before_thread_started.cpp
@@ -37,6 +37,7 @@ void create_detached_thread() {
pthread_mutex_lock(&mutex);
int res = pthread_create(&thread_id, &attr, func, arg);
assert(res == 0);
+ pthread_attr_destroy(&attr);
}
int main() {
More information about the llvm-commits
mailing list