Do not call ReplaceCFAllocator() before __CFInitialize(), otherwise crashes are possi...
authorAlexander Potapenko <glider@google.com>
Tue, 16 Oct 2012 16:58:10 +0000 (16:58 +0000)
committerAlexander Potapenko <glider@google.com>
Tue, 16 Oct 2012 16:58:10 +0000 (16:58 +0000)
Fixes http://code.google.com/p/address-sanitizer/issues/detail?id=122

llvm-svn: 166029

compiler-rt/lib/asan/asan_mac.cc

index 11b0a56..f3ea770 100644 (file)
@@ -131,7 +131,14 @@ bool AsanInterceptsSignal(int signum) {
 }
 
 void AsanPlatformThreadInit() {
-  ReplaceCFAllocator();
+  // For the first program thread, we can't replace the allocator before
+  // __CFInitialize() has been called. If it hasn't, we'll call
+  // ReplaceCFAllocator() later on this thread.
+  // For other threads __CFInitialize() has been called before their creation.
+  // See also asan_malloc_mac.cc.
+  if (((CFRuntimeBase*)kCFAllocatorSystemDefault)->_cfisa) {
+    ReplaceCFAllocator();
+  }
 }
 
 AsanLock::AsanLock(LinkerInitialized) {