Last active
April 7, 2022 19:25
-
-
Save mafintosh/e52b32d5f7a7e7cff30d327d3ad70707 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
#include <dlfcn.h> | |
static int mallocs_active = 0; | |
void *malloc(size_t size) { | |
void * (*real_malloc)(size_t); | |
real_malloc = dlsym(RTLD_NEXT, "malloc"); | |
mallocs_active++; | |
void *ptr = real_malloc(size); | |
fprintf(stderr, "DEBUG: malloc(%zu) = %p, pointers=%i\n", size, ptr, mallocs_active); | |
return ptr; | |
} | |
void free(void *ptr) { | |
void * (*real_free)(void *ptr); | |
real_free = dlsym(RTLD_NEXT, "free"); | |
mallocs_active--; | |
fprintf(stderr, "DEBUG: free(%p), pointers=%i\n", ptr, mallocs_active); | |
real_free(ptr); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment