ust: mallocwrap: add
[ust.git] / libmallocwrap / mallocwrap.c
diff --git a/libmallocwrap/mallocwrap.c b/libmallocwrap/mallocwrap.c
new file mode 100644 (file)
index 0000000..48dab0a
--- /dev/null
@@ -0,0 +1,19 @@
+#define _GNU_SOURCE
+#include <dlfcn.h>
+#include <sys/types.h>
+#include <stdio.h>
+
+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);
+}
This page took 0.023411 seconds and 4 git commands to generate.