From e541a28d5fdb3b64e972189458d7b2269d1603d4 Mon Sep 17 00:00:00 2001 From: Pierre-Marc Fournier Date: Tue, 17 Feb 2009 15:37:40 -0500 Subject: [PATCH] ust: mallocwrap: add --- libmallocwrap/Makefile | 4 ++++ libmallocwrap/mallocwrap.c | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 libmallocwrap/Makefile create mode 100644 libmallocwrap/mallocwrap.c diff --git a/libmallocwrap/Makefile b/libmallocwrap/Makefile new file mode 100644 index 0000000..ac7ff69 --- /dev/null +++ b/libmallocwrap/Makefile @@ -0,0 +1,4 @@ +all: libmallocwrap.so + +libmallocwrap.so: mallocwrap.c + gcc -shared -fPIC -g -ldl -o libmallocwrap.so mallocwrap.c diff --git a/libmallocwrap/mallocwrap.c b/libmallocwrap/mallocwrap.c new file mode 100644 index 0000000..48dab0a --- /dev/null +++ b/libmallocwrap/mallocwrap.c @@ -0,0 +1,19 @@ +#define _GNU_SOURCE +#include +#include +#include + +void *(*plibc_malloc)(size_t size) = NULL; + +void *malloc(size_t size) +{ + if(plibc_malloc == NULL) { + plibc_malloc = dlsym(RTLD_NEXT, "malloc"); + if(plibc_malloc == NULL) { + fprintf(stderr, "mallocwrap: unable to find malloc\n"); + return NULL; + } + } + fprintf(stderr, "mallocating size %d\n", size); + return plibc_malloc(size); +} -- 2.34.1