Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame^] | 1 | // Check that we can store lots of stack frames if asked to. |
| 2 | |
| 3 | // RUN: %clangxx_asan -O0 %s -o %t 2>&1 |
| 4 | // RUN: env ASAN_OPTIONS=malloc_context_size=120:redzone=512 not %run %t 2>&1 | FileCheck %s |
| 5 | #include <stdlib.h> |
| 6 | #include <stdio.h> |
| 7 | |
| 8 | template <int depth> |
| 9 | struct DeepFree { |
| 10 | static void free(char *x) { |
| 11 | DeepFree<depth - 1>::free(x); |
| 12 | } |
| 13 | }; |
| 14 | |
| 15 | template<> |
| 16 | struct DeepFree<0> { |
| 17 | static void free(char *x) { |
| 18 | ::free(x); |
| 19 | } |
| 20 | }; |
| 21 | |
| 22 | int main() { |
| 23 | char *x = (char*)malloc(10); |
| 24 | // deep_free(x); |
| 25 | DeepFree<200>::free(x); |
| 26 | return x[5]; |
| 27 | // CHECK: {{.*ERROR: AddressSanitizer: heap-use-after-free on address}} |
| 28 | // CHECK: DeepFree<36> |
| 29 | // CHECK: DeepFree<98> |
| 30 | // CHECK: DeepFree<115> |
| 31 | } |