Single 4k file only. No dependencies. Zero configuration. Logs parameters, return value and call stack. No need to rebuild application.
Download: log-malloc.c.
Build: gcc -DWITH_PTHREADS -nostartfiles --shared -fPIC -g -ldl -o log-malloc.so log-malloc.c
Build without pthread locks: gcc -nostartfiles --shared -fPIC -g -ldl -o log-malloc.so log-malloc.c
Usage:
LD_PRELOAD=./log-malloc.so command args ...
Redirect output to file:
LD_PRELOAD=./log-malloc.so command args ... 200>filename
Sample output: log-malloc.log.txt
Use addr2line tool from GNU binutils to convert 0x addresses into source code line numbers.
Thanks Dan Carpenter for help in fixing bug.