Skip to content

Instantly share code, notes, and snippets.

@mheffner
Created August 18, 2009 13:57
Show Gist options
  • Save mheffner/169723 to your computer and use it in GitHub Desktop.
Save mheffner/169723 to your computer and use it in GitHub Desktop.
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <dlfcn.h>
static void *(*malloc_internal)(size_t size);
void __attribute__ ((constructor)) init(void);
/* Library constructor */
void
init(void)
{
malloc_internal = dlsym(RTLD_NEXT, "malloc");
}
void *
malloc(size_t size)
{
void *ret;
ret = malloc_internal(size);
printf ("Malloc request for %zd bytes got memory: %p\n", size, ret);
return ret;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment