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