Home | History | Annotate | Download | only in Linux
      1 // Check that we detect malloc/delete mismatch only if the approptiate flag
      2 // is set.
      3 
      4 // RUN: %clangxx_asan -g %s -o %t 2>&1
      5 
      6 // Find error and provide malloc context.
      7 // RUN: ASAN_OPTIONS=alloc_dealloc_mismatch=1 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=ALLOC-STACK
      8 
      9 // No error here.
     10 // RUN: ASAN_OPTIONS=alloc_dealloc_mismatch=0 %run %t
     11 
     12 // Also works if no malloc context is available.
     13 // RUN: ASAN_OPTIONS=alloc_dealloc_mismatch=1:malloc_context_size=0:fast_unwind_on_malloc=0 not %run %t 2>&1 | FileCheck %s
     14 // RUN: ASAN_OPTIONS=alloc_dealloc_mismatch=1:malloc_context_size=0:fast_unwind_on_malloc=1 not %run %t 2>&1 | FileCheck %s
     15 // XFAIL: arm-linux-gnueabi
     16 #include <stdlib.h>
     17 
     18 static volatile char *x;
     19 
     20 int main() {
     21   x = (char*)malloc(10);
     22   x[0] = 0;
     23   delete x;
     24 }
     25 // CHECK: ERROR: AddressSanitizer: alloc-dealloc-mismatch (malloc vs operator delete) on 0x
     26 // CHECK-NEXT: #0{{.*}}operator delete
     27 // CHECK: #{{.*}}main
     28 // CHECK: is located 0 bytes inside of 10-byte region
     29 // CHECK-NEXT: allocated by thread T0 here:
     30 // ALLOC-STACK-NEXT: #0{{.*}}malloc
     31 // ALLOC-STACK: #{{.*}}main
     32 // CHECK: HINT: {{.*}} you may set ASAN_OPTIONS=alloc_dealloc_mismatch=0
     33