If you just want to get the place where a large amount of memory is being requested from, the easiest way would be to install the malloc function or create a new library with a call to malloc and track the size of the malloc function form. I'm not talking about implementing a malloc call. LD_PRELOAD this library for your application.
Here is a sample code:
#include <stdio.h> #include <sys/time.h> #include <dlfcn.h> #include <stdlib.h> #include <sys/errno.h> #ifndef RTLD_NEXT #define RTLD_NEXT ((void *)-1) #endif int init_lib(void) { return 0; } void *malloc(size_t size) { /* do required checks on size here */ return ((void* (*)(size_t))(dlsym(RTLD_NEXT, "malloc")))(size); }
You can very well modify this code to do some extra things.
Vikram.exe
source share