Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 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 |
Stephen Hines | 6a211c5 | 2014-07-21 00:49:56 -0700 | [diff] [blame] | 7 | // XFAIL: arm-linux-gnueabi |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame^] | 8 | // XFAIL: armv7l-unknown-linux-gnueabihf |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 9 | |
| 10 | #include <stdlib.h> |
| 11 | #include <string.h> |
| 12 | int main(int argc, char **argv) { |
| 13 | char *x = (char*)malloc(10 * sizeof(char)); |
| 14 | memset(x, 0, 10); |
| 15 | int res = x[argc]; |
| 16 | free(x); |
| 17 | free(x + argc - 1); // BOOM |
| 18 | // CHECK: AddressSanitizer: attempting double-free{{.*}}in thread T0 |
| 19 | // CHECK: #0 0x{{.*}} in {{.*}}free |
| 20 | // CHECK: #1 0x{{.*}} in main {{.*}}double-free.cc:[[@LINE-3]] |
| 21 | // CHECK: freed by thread T0 here: |
| 22 | // MALLOC-CTX: #0 0x{{.*}} in {{.*}}free |
| 23 | // MALLOC-CTX: #1 0x{{.*}} in main {{.*}}double-free.cc:[[@LINE-7]] |
| 24 | // CHECK: allocated by thread T0 here: |
| 25 | // MALLOC-CTX: double-free.cc:[[@LINE-12]] |
| 26 | return res; |
| 27 | } |