#define _GNU_SOURCE #include #include #define FREE_DELAY 100000 static void *free_delay_queue[FREE_DELAY]; static int free_delay_pos; static void (*orig_free)(void *); static pthread_mutex_t free_delay_mutex = PTHREAD_MUTEX_INITIALIZER; void free(void *ptr) { if (!ptr) return; pthread_mutex_lock(&free_delay_mutex); if (!orig_free) orig_free = dlsym(RTLD_NEXT, "free"); orig_free(free_delay_queue[free_delay_pos]); free_delay_queue[free_delay_pos] = ptr; free_delay_pos++; free_delay_pos %= FREE_DELAY; pthread_mutex_unlock(&free_delay_mutex); }