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_opts=malloc_context_size=0:fast_unwind_on_malloc=0 not %run %t 2>&1 | FileCheck %s
6 // RUN: %env_asan_opts=malloc_context_size=0:fast_unwind_on_malloc=1 not %run %t 2>&1 | FileCheck %s
7
8 // RUN: %clangxx_asan -O0 -fsanitize-recover=address %s -o %t 2>&1
9 // RUN: %env_asan_opts=halt_on_error=false %run %t 2>&1 | FileCheck %s --check-prefix CHECK-RECOVER
10
11 // XFAIL: arm-linux-gnueabi
12 // XFAIL: armv7l-unknown-linux-gnueabihf
13
14 #include <stdlib.h>
15 #include <string.h>
main(int argc,char ** argv)16 int main(int argc, char **argv) {
17 char *x = (char*)malloc(10 * sizeof(char));
18 memset(x, 0, 10);
19 int res = x[argc];
20 free(x);
21 free(x + argc - 1); // BOOM
22 // CHECK: AddressSanitizer: attempting double-free{{.*}}in thread T0
23 // CHECK: #0 0x{{.*}} in {{.*}}free
24 // CHECK: #1 0x{{.*}} in main {{.*}}double-free.cc:[[@LINE-3]]
25 // CHECK: freed by thread T0 here:
26 // MALLOC-CTX: #0 0x{{.*}} in {{.*}}free
27 // MALLOC-CTX: #1 0x{{.*}} in main {{.*}}double-free.cc:[[@LINE-7]]
28 // CHECK: allocated by thread T0 here:
29 // MALLOC-CTX: double-free.cc:[[@LINE-12]]
30 // CHECK-RECOVER: AddressSanitizer: attempting double-free{{.*}}in thread T0
31 // CHECK-RECOVER-NOT: AddressSanitizer CHECK failed:
32 return res;
33 }
34