11 static void * (*real_malloc)(size_t) = NULL;
12 static void (*real_free)(void *ptr) = NULL;
14 static void __my_alloc_init(void)
17 real_malloc = (void *(*)(size_t))dlsym(RTLD_NEXT, "malloc");
18 real_free = (void (*)(void *))dlsym(RTLD_NEXT, "free");
19 if (real_malloc == NULL || real_free == NULL) {
20 fprintf(stderr, "Error in `dlsym`: %s\n", dlerror());
25 void *myMalloc(size_t size)
27 if (real_malloc == NULL)
30 return real_malloc(size);
33 void myFree(void *ptr)
35 if (real_free == NULL)
41 void * operator new(size_t size)
43 return myMalloc(size);
46 void operator delete(void *p)