1 // Test handling of arg and retval of child thread.
3 // RUN: %clangxx_lsan -pthread %s -o %t
4 // RUN: not %run %t 10 1 0 0 2>&1 | FileCheck %s --check-prefixes=LEAK,LEAK123
5 // RUN: not %run %t 10 0 1 0 2>&1 | FileCheck %s --check-prefixes=LEAK,LEAK234
6 // RUN: not %run %t 10 0 0 1 2>&1 | FileCheck %s --check-prefixes=LEAK,LEAK234
7 // RUN: %run %t 10 0 0 0
9 // This test appears to be flaky on x86_64-darwin buildbots.
10 // UNSUPPORTED: darwin
15 #include <sanitizer/lsan_interface.h>
21 static void *thread_free(void *args
) {
27 int main(int argc
, char **argv
) {
28 int n
= atoi(argv
[1]);
29 leak_arg
= atoi(argv
[2]);
30 leak_retval
= atoi(argv
[3]);
31 detach
= atoi(argv
[4]);
32 for (int i
= 0; i
< n
; ++i
) {
33 pthread_t threads
[10];
35 for (auto &thread
: threads
) {
36 pthread_create(&thread
, 0, thread_free
, malloc(123));
37 if (__lsan_do_recoverable_leak_check())
41 for (auto &thread
: threads
) {
43 pthread_detach(thread
);
47 pthread_join(thread
, &retval
);
55 // LEAK: LeakSanitizer: detected memory leaks
57 // LEAK234: in thread_free