Created
September 14, 2020 13:27
-
-
Save drrost/bb33af18253ee4e81c330fd45d300551 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static void *(*real_malloc)(unsigned long) = 0; // 1 | |
int malloc_counter = 0; // 2 | |
static void malloc_init(void) { // 3 | |
real_malloc = (void *(*)(unsigned long))dlsym(RTLD_NEXT, "malloc"); | |
if (real_malloc == 0) | |
fprintf(stderr, "Error in `dlsym`: %s\n", dlerror()); | |
} | |
void *malloc(unsigned long size) { // 4 | |
if (real_malloc == 0) | |
malloc_init(); // 5 | |
malloc_counter++; // 6 | |
return real_malloc(size); // 7 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment