[llvm-commits] [compiler-rt] r158921 - in /compiler-rt/trunk/lib/asan/tests: asan_mac_test.h asan_mac_test.mm asan_test.cc

Alexander Potapenko glider at google.com
Thu Jun 21 09:08:11 PDT 2012


Author: glider
Date: Thu Jun 21 11:08:11 2012
New Revision: 158921

URL: http://llvm.org/viewvc/llvm-project?rev=158921&view=rev
Log:
Add a test for issue 81 -- AddressSanitizerMac.DISABLED_CFAllocatorDefaultDoubleFree_ChildPhread

Modified:
    compiler-rt/trunk/lib/asan/tests/asan_mac_test.h
    compiler-rt/trunk/lib/asan/tests/asan_mac_test.mm
    compiler-rt/trunk/lib/asan/tests/asan_test.cc

Modified: compiler-rt/trunk/lib/asan/tests/asan_mac_test.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/tests/asan_mac_test.h?rev=158921&r1=158920&r2=158921&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/tests/asan_mac_test.h (original)
+++ compiler-rt/trunk/lib/asan/tests/asan_mac_test.h Thu Jun 21 11:08:11 2012
@@ -1,5 +1,5 @@
 extern "C" {
-  void CFAllocatorDefaultDoubleFree();
+  void *CFAllocatorDefaultDoubleFree(void *unused);
   void CFAllocatorSystemDefaultDoubleFree();
   void CFAllocatorMallocDoubleFree();
   void CFAllocatorMallocZoneDoubleFree();

Modified: compiler-rt/trunk/lib/asan/tests/asan_mac_test.mm
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/tests/asan_mac_test.mm?rev=158921&r1=158920&r2=158921&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/tests/asan_mac_test.mm (original)
+++ compiler-rt/trunk/lib/asan/tests/asan_mac_test.mm Thu Jun 21 11:08:11 2012
@@ -9,7 +9,8 @@
 #import <Foundation/NSObject.h>
 #import <Foundation/NSURL.h>
 
-void CFAllocatorDefaultDoubleFree() {
+// This is a (void*)(void*) function so it can be passed to pthread_create.
+void *CFAllocatorDefaultDoubleFree(void *unused) {
   void *mem =  CFAllocatorAllocate(kCFAllocatorDefault, 5, 0);
   CFAllocatorDeallocate(kCFAllocatorDefault, mem);
   CFAllocatorDeallocate(kCFAllocatorDefault, mem);

Modified: compiler-rt/trunk/lib/asan/tests/asan_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/tests/asan_test.cc?rev=158921&r1=158920&r2=158921&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/tests/asan_test.cc (original)
+++ compiler-rt/trunk/lib/asan/tests/asan_test.cc Thu Jun 21 11:08:11 2012
@@ -1902,10 +1902,20 @@
 #include "asan_mac_test.h"
 TEST(AddressSanitizerMac, CFAllocatorDefaultDoubleFree) {
   EXPECT_DEATH(
-      CFAllocatorDefaultDoubleFree(),
+      CFAllocatorDefaultDoubleFree(NULL),
       "attempting double-free");
 }
 
+void CFAllocator_DoubleFreeOnPthread() {
+  pthread_t child;
+  pthread_create(&child, NULL, CFAllocatorDefaultDoubleFree, NULL);
+  pthread_join(child, NULL);  // Shouldn't be reached.
+}
+
+TEST(AddressSanitizerMac, DISABLED_CFAllocatorDefaultDoubleFree_ChildPhread) {
+  EXPECT_DEATH(CFAllocator_DoubleFreeOnPthread(), "attempting double-free");
+} 
+
 // TODO(glider): figure out whether we still need these tests. Is it correct
 // to intercept the non-default CFAllocators?
 TEST(AddressSanitizerMac, DISABLED_CFAllocatorSystemDefaultDoubleFree) {
@@ -1914,6 +1924,7 @@
       "attempting double-free");
 }
 
+// We're intercepting malloc, so kCFAllocatorMalloc is routed to ASan.
 TEST(AddressSanitizerMac, CFAllocatorMallocDoubleFree) {
   EXPECT_DEATH(CFAllocatorMallocDoubleFree(), "attempting double-free");
 }





More information about the llvm-commits mailing list