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 5 #include <stdlib.h> 6 #include <unistd.h> 7 #include <sanitizer/allocator_interface.h> 8 9 static void *glob_ptr; 10 11 extern "C" { 12 void __sanitizer_free_hook(const volatile void *ptr) { 13 if (ptr == glob_ptr) { 14 *(int*)ptr = 0; 15 write(1, "FreeHook\n", sizeof("FreeHook\n")); 16 } 17 } 18 } 19 20 int main() { 21 int *x = (int*)malloc(100); 22 x[0] = 42; 23 glob_ptr = x; 24 int *y = (int*)realloc(x, 200); 25 // Verify that free hook was called and didn't spoil the memory. 26 if (y[0] != 42) { 27 _exit(1); 28 } 29 write(1, "Passed\n", sizeof("Passed\n")); 30 free(y); 31 // CHECK: FreeHook 32 // CHECK: Passed 33 return 0; 34 } 35