[ASAN][LSAN] Ignore main or uninitialized thead in pthread_exit
authorVitaly Buka <vitalybuka@google.com>
Fri, 12 May 2023 05:56:27 +0000 (22:56 -0700)
committerVitaly Buka <vitalybuka@google.com>
Fri, 12 May 2023 05:58:09 +0000 (22:58 -0700)
Fix crash on CHECK in ThreadArgRetval::Finish().

compiler-rt/lib/asan/asan_interceptors.cpp
compiler-rt/lib/lsan/lsan_interceptors.cpp

index 7d658e5..b5767ea 100644 (file)
@@ -23,6 +23,7 @@
 #include "asan_suppressions.h"
 #include "asan_thread.h"
 #include "lsan/lsan_common.h"
+#include "sanitizer_common/sanitizer_internal_defs.h"
 #include "sanitizer_common/sanitizer_libc.h"
 
 // There is no general interception at all on Fuchsia.
@@ -263,7 +264,9 @@ INTERCEPTOR(int, pthread_detach, void *thread) {
 }
 
 INTERCEPTOR(int, pthread_exit, void *retval) {
-  asanThreadArgRetval().Finish(GetThreadSelf(), retval);
+  AsanThread *t = GetCurrentThread();
+  if (t && t->tid() != kMainTid)
+    asanThreadArgRetval().Finish(GetThreadSelf(), retval);
   return REAL(pthread_exit)(retval);
 }
 
index 2a35572..b726816 100644 (file)
@@ -489,7 +489,9 @@ INTERCEPTOR(int, pthread_detach, void *thread) {
 }
 
 INTERCEPTOR(int, pthread_exit, void *retval) {
-  GetThreadArgRetval().Finish(GetThreadSelf(), retval);
+  ThreadContextLsanBase *t = GetCurrentThread();
+  if (t && t->tid != kMainTid)
+    GetThreadArgRetval().Finish(GetThreadSelf(), retval);
   return REAL(pthread_exit)(retval);
 }