Home | History | Annotate | Download | only in TestCases
      1 // RUN: %clangxx_asan -O0 %s -o %t 2>&1
      2 // RUN: not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=MALLOC-CTX
      3 
      4 // Also works if no malloc context is available.
      5 // RUN: env ASAN_OPTIONS=malloc_context_size=0:fast_unwind_on_malloc=0 not %run %t 2>&1 | FileCheck %s
      6 // RUN: env ASAN_OPTIONS=malloc_context_size=0:fast_unwind_on_malloc=1 not %run %t 2>&1 | FileCheck %s
      7 // XFAIL: arm-linux-gnueabi
      8 
      9 #include <stdlib.h>
     10 #include <string.h>
     11 int main(int argc, char **argv) {
     12   char *x = (char*)malloc(10 * sizeof(char));
     13   memset(x, 0, 10);
     14   int res = x[argc];
     15   free(x);
     16   free(x + argc - 1);  // BOOM
     17   // CHECK: AddressSanitizer: attempting double-free{{.*}}in thread T0
     18   // CHECK: #0 0x{{.*}} in {{.*}}free
     19   // CHECK: #1 0x{{.*}} in main {{.*}}double-free.cc:[[@LINE-3]]
     20   // CHECK: freed by thread T0 here:
     21   // MALLOC-CTX: #0 0x{{.*}} in {{.*}}free
     22   // MALLOC-CTX: #1 0x{{.*}} in main {{.*}}double-free.cc:[[@LINE-7]]
     23   // CHECK: allocated by thread T0 here:
     24   // MALLOC-CTX: double-free.cc:[[@LINE-12]]
     25   return res;
     26 }
     27