About LibCalloc
This library helps to check memory allocation
Usage
This library need to be link to the application under debugging or to be preloaded before starting the application. Depending to the environment variable MEMORY_ALLOCATION_, on signal catch or on program exit, it will display lots of useful debugging information on previously allocated memory blocks such as:
- 3 or 5 character status
- first is F for freed, A for allocated, and R for reallocated,
- second is . or B if the block begin is corrupted,
- third is . or E if the block end is corrupted,
- if block has be reallocated, forth is . or B if the block begin is corrupted,
- if block has be reallocated, fiveth is . or E if the block end is corrupted.
- last reference pointer,
- allocated block size (in bytes),
- source file and line number of initial allocation or last re-allocation and, if the block has already been free, its source file and line number. Those information are only avaiable if snd/calloc.h has been include in all files and that program has been linked with LibCalloc.
Variable
If MEMORY_ALLOCATION_ contains 't' (for tolerant) or any value greater than 1, LibCalloc activates the display of memory allocation checks on exit and on signal catch (for signal SIGSEGV, SIGILL and SIGBUS).
If MEMORY_ALLOCATION_ contains 'y' (for yes) or 1, LibCalloc hangs on first memory corruption (check are done on free). A coredump will be generated.
LibCalloc prints on stderr traces for every allocation and every freeing.
Examples
The following example shows what is needed during linking to get memory allocation checker activated.
echo '#includeint main (int argc, char *argv[]) { char *a = malloc (8); char *b = malloc (4); switch (argv[argc-1][0]) { case '´a´': a[8] = 0; case '´b´': b[-1] = 0; break; } free (a); return 0; }' > test.c gcc -lcalloc test.c MEMORY_ALLOCATION_=t ./a.out a
The following example shows what is needed at execution time.
echo '#includeint main (int argc, char *argv[]) { char *a = malloc (8); char *b = malloc (4); switch (argv[argc-1][0]) { case '´a´': a[8] = 0; case '´b´': b[-1] = 0; break; } free (a); return 0; }' > test.c gcc -g test.c LD_PRELOAD=/usr/lib/libcalloc.so MEMORY_ALLOCATION_=y ./a.out b gdb a.out core -q << EOF bt EOF
Screen-shot
Shell view
Downloads
Source packages
Debian packages
- LibCalloc version 1.2.2 (i386)
- LibCalloc version 1.2.2 (amd64)
- LibCalloc version 1.2.2 (dev i386)
- LibCalloc version 1.2.2 (dev amd64)
Requirements
This library only need a C compiler to be build.
To install, one only needs to
- unpack the archive,
- do a 'make',
- and a 'make install'.
Changelogs
LibCalloc 1.2.2 (Thu, 28 Mar 2024 07:45:15 +0100)
- Fixes from gcc 12 compilation warnings
LibCalloc 1.2.1 (Mon, 02 Jun 2014 21:10:26 +0200)
- Split debian packaging
- Minor cleanings
LibCalloc 1.2 (Tue, 17 Sep 2013 12:15:50 +0200)
- First public version
- Adaptation for gcc 4.7
- Fix memory allocation checker (internal printf)
- Adapt to 64bit compiler
LibCalloc 1.0 (Sat, 8 Jun 2013 19:53:51 +0200)
- Enhance consistency checking for reallocation
- Enhance report on consistency checking
- Enable malloc hooks
- Tolerance can be 2 to 9 or T
- Improvement of display memory
LibCalloc 0.1 (Sun, 14 Jun 2009 23:06:57 +0200)
- Initial version