| 1 | // RUN: %clangxx_asan -O0 %s -o %t |
| 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 | // REQUIRES: stable-runtime |
| 8 | |
| 9 | #include <stdlib.h> |
| 10 | #include <string.h> |
| 11 | int main(int argc, char **argv) { |
| 12 | char *x = (char*)malloc(size: 10 * sizeof(char)); |
| 13 | memset(s: x, c: 0, n: 10); |
| 14 | int res = x[argc]; |
| 15 | free(ptr: x + 5); // BOOM |
| 16 | // CHECK: AddressSanitizer: attempting free on address{{.*}}in thread T0 |
| 17 | // CHECK: invalid-free.cpp:[[@LINE-2]] |
| 18 | // CHECK: is located 5 bytes inside of 10-byte region |
| 19 | // CHECK: allocated by thread T0 here: |
| 20 | // MALLOC-CTX: invalid-free.cpp:[[@LINE-8]] |
| 21 | return res; |
| 22 | } |
| 23 | |