Fix use-after-pthread_exit in a test.
HWASan reports access to a local variable after the owning thread has
called pthread_exit.
Bug: 114279110
Test: enable hwasan in tests/Android.bp; run pthread_DeathTest.pthread_bug_37410
Change-Id: Ic04a2b3dce092d7ab3cbefab1da64731e0c7afb9
diff --git a/tests/pthread_test.cpp b/tests/pthread_test.cpp
index 1c57264..0918d0e 100644
--- a/tests/pthread_test.cpp
+++ b/tests/pthread_test.cpp
@@ -336,11 +336,14 @@
static void* thread_fn(void* arg) {
TestBug37410* data = reinterpret_cast<TestBug37410*>(arg);
+ // Unlocking data->mutex will cause the main thread to exit, invalidating *data. Save the handle.
+ pthread_t main_thread = data->main_thread;
+
// Let the main thread know we're running.
pthread_mutex_unlock(&data->mutex);
// And wait for the main thread to exit.
- pthread_join(data->main_thread, nullptr);
+ pthread_join(main_thread, nullptr);
return nullptr;
}