diff --git a/compiler-rt/test/lsan/TestCases/many_threads_detach.cpp b/compiler-rt/test/lsan/TestCases/many_threads_detach.cpp index 857766ddee24e..6909a483aa4ce 100644 --- a/compiler-rt/test/lsan/TestCases/many_threads_detach.cpp +++ b/compiler-rt/test/lsan/TestCases/many_threads_detach.cpp @@ -5,6 +5,7 @@ #include #include +#include // Number of threads to create. This value is greater than kMaxThreads in // lsan_thread.cpp so that we can test that thread contexts are not being @@ -18,8 +19,8 @@ void *null_func(void *args) { int main(void) { for (size_t i = 0; i < kTestThreads; i++) { pthread_t thread; - pthread_create(&thread, NULL, null_func, NULL); - pthread_detach(thread); + if (pthread_create(&thread, NULL, null_func, NULL) == 0) + pthread_detach(thread); } return 0; }