blob: 2966aadff706c077c459cd9dea24173c3f4a217e [file] [log] [blame]
Stephen Hines2d1fdb22014-05-28 23:58:16 -07001// 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.
Pirama Arumuga Nainarcdce50b2015-07-01 12:26:56 -07005// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:malloc_context_size=0:fast_unwind_on_malloc=0 not %run %t 2>&1 | FileCheck %s
6// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:malloc_context_size=0:fast_unwind_on_malloc=1 not %run %t 2>&1 | FileCheck %s
Stephen Hines6a211c52014-07-21 00:49:56 -07007// XFAIL: arm-linux-gnueabi
Stephen Hines6d186232014-11-26 17:56:19 -08008// XFAIL: armv7l-unknown-linux-gnueabihf
Stephen Hines2d1fdb22014-05-28 23:58:16 -07009
10#include <stdlib.h>
11#include <string.h>
12int 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}