From a0b38a3f311b477cd1f63db0cb55fec4a4d9b427 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Thu, 31 Aug 2017 11:27:45 +0200 Subject: [PATCH] Try to memcheck --- src/main.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/main.c b/src/main.c index 316373c..afb0ab6 100644 --- a/src/main.c +++ b/src/main.c @@ -12,6 +12,34 @@ #include "crypto.h" +#define _GNU_SOURCE +#include +#include + +static void* (*real_malloc)(size_t)=NULL; + +static void mtrace_init(void) +{ + real_malloc = dlsym(RTLD_NEXT, "malloc"); + if (NULL == real_malloc) { + fprintf(stderr, "Error in `dlsym`: %s\n", dlerror()); + } +} + +void *malloc(size_t size) +{ + mtrace_init(); + if(real_malloc==NULL) { + mtrace_init(); + } + + void *p = NULL; + fprintf(stderr, "malloc(%d) = ", size); + p = real_malloc(size); + fprintf(stderr, "%p\n", p); + return p; +} + int main(int argc, char **argv) { const char *ubus_socket = NULL; int ch;