]>
Commit | Line | Data |
---|---|---|
1a4d82fc JJ |
1 | // Check that free hook doesn't conflict with Realloc. |
2 | // RUN: %clangxx_asan -O2 %s -o %t | |
3 | // RUN: %run %t 2>&1 | FileCheck %s | |
4 | #include <stdlib.h> | |
5 | #include <unistd.h> | |
6 | ||
7 | static void *glob_ptr; | |
8 | ||
9 | extern "C" { | |
10 | void __asan_free_hook(void *ptr) { | |
11 | if (ptr == glob_ptr) { | |
12 | *(int*)ptr = 0; | |
13 | write(1, "FreeHook\n", sizeof("FreeHook\n")); | |
14 | } | |
15 | } | |
16 | } | |
17 | ||
18 | int main() { | |
19 | int *x = (int*)malloc(100); | |
20 | x[0] = 42; | |
21 | glob_ptr = x; | |
22 | int *y = (int*)realloc(x, 200); | |
23 | // Verify that free hook was called and didn't spoil the memory. | |
24 | if (y[0] != 42) { | |
25 | _exit(1); | |
26 | } | |
27 | write(1, "Passed\n", sizeof("Passed\n")); | |
28 | free(y); | |
29 | // CHECK: FreeHook | |
30 | // CHECK: Passed | |
31 | return 0; | |
32 | } |