First page Back Continue Last page Overview Graphics
Malloc debugging
MALLOC_CHECK_ environment variable
- Set to 2 - aborts as soon as it sees error
- Still doesn't show point of corruption
electric_fence
- Modified malloc implementation
- Build with -lefence at link time
- Segfaults much sooner - often at point of corruption
- More details see man libefence
Notes:
Recent Linux glibc's have a facility called MALLOC_CHECK_.
Doing export MALLOC_CHECK_=2 in your shell will call your next run of badmalloc to emit a SIGABORT; which shows up in gdb inside malloc. Still not too useful.
Electric fence is a modified malloc implementation. Recompile with:
gcc badmalloc.c -g -o badmalloc -lefence
now run this under gdb and you will see the failure at the point of corruption - the array assignment.
There are subtleties to efence - look at the docs.