Tips I found useful while dealing with programming issues (in C).

Contents

Debug memory errors

For debugging memory errors valgrind is very useful tool.
broken program would show
$ ./program
*** glibc detected *** double free or corruption (out): 0x08138a80 ***
Aborted

valgrind shows where the problem occurs
$ valgrind ./program
==31784== Invalid free() / delete / delete[]
==31784== at 0x1B90579D: free (vg_replace_malloc.c:152)
==31784== by 0x1BB2E6CD: xfree (xmalloc.c:200)
==31784== by 0x1BB25095: _xFreePtr (mem.c:613)

For debugging with valgrind I use following configuration:
~/.valgrindrc file
--tool=memcheck
--memcheck:leak-check=yes
--memcheck:show-reachable=yes
--num-callers=16
--memcheck:db-attach=no


To disable glibc memory errors detection you need to set MALLOC_CHECK_ environment variable to 0 (note ending underscore).
$ export MALLOC_CHECK_=0

More resources:

→ Go back to Linux resources page

Jan Słupski, email: jslupski at juljas dot net