Skip to content

Commit a79098b

Browse files
authored
[compiler-rt] Destroy pthread attrs after use in tests (#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.
1 parent 0dcb16e commit a79098b

File tree

3 files changed

+3
-0
lines changed

3 files changed

+3
-0
lines changed

compiler-rt/test/asan/TestCases/Posix/fake_stack_gc.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ int main(void) {
8989

9090
pthread_t tid;
9191
assert(pthread_create(&tid, &attr, Thread, alt_stack) == 0);
92+
assert(pthread_attr_destroy(&attr) == 0);
9293

9394
pthread_join(tid, nullptr);
9495

compiler-rt/test/asan/TestCases/Posix/unpoison-alternate-stack.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ int main() {
159159
pthread_attr_init(&ThreadAttr);
160160
pthread_attr_setstack(&ThreadAttr, Mapping, DefaultStackSize);
161161
pthread_create(&Thread, &ThreadAttr, &threadFun, (void *)&AltStack);
162+
pthread_attr_destroy(&ThreadAttr);
162163

163164
pthread_join(Thread, nullptr);
164165

compiler-rt/test/lsan/TestCases/leak_check_before_thread_started.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ void create_detached_thread() {
3737
pthread_mutex_lock(&mutex);
3838
int res = pthread_create(&thread_id, &attr, func, arg);
3939
assert(res == 0);
40+
pthread_attr_destroy(&attr);
4041
}
4142

4243
int main() {

0 commit comments

Comments
 (0)