1 // RUN: %clang_scudo %s -o %t 2 // RUN: %run %t 2>&1 3 4 // Verifies that calling malloc in a preinit_array function succeeds, and that 5 // the resulting pointer can be freed at program termination. 6 7 #include <malloc.h> 8 #include <stdlib.h> 9 #include <string.h> 10 11 static void *global_p = nullptr; 12 __init(void)13void __init(void) { 14 global_p = malloc(1); 15 if (!global_p) 16 exit(1); 17 } 18 __fini(void)19void __fini(void) { 20 if (global_p) 21 free(global_p); 22 } 23 main(int argc,char ** argv)24int main(int argc, char **argv) 25 { 26 void *p = malloc(1); 27 if (!p) 28 return 1; 29 free(p); 30 31 return 0; 32 } 33 34 __attribute__((section(".preinit_array"), used)) 35 void (*__local_preinit)(void) = __init; 36 __attribute__((section(".fini_array"), used)) 37 void (*__local_fini)(void) = __fini; 38 39