Aller au contenu | Aller au menu | Rechercher

Blog | Budget | Gallery | Sys Info |

LibCalloc - a memory allocation checker library

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:

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 '#include 
int 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 '#include 
int 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

Requirements

This library only need a C compiler to be build.

To install, one only needs to

Changelogs

LibCalloc 1.2.2 (Thu, 28 Mar 2024 07:45:15 +0100)

LibCalloc 1.2.1 (Mon, 02 Jun 2014 21:10:26 +0200)

LibCalloc 1.2 (Tue, 17 Sep 2013 12:15:50 +0200)

LibCalloc 1.0 (Sat, 8 Jun 2013 19:53:51 +0200)

LibCalloc 0.1 (Sun, 14 Jun 2009 23:06:57 +0200)

Page créee/modifié le 28 mars 2024.

Envoyez tout commentaire à Laurent Mazet

Ce site fonctionne avec des logiciels libres tels que Debian GNU/Linux, Apache, MySQL et PHP

Valid XHTML 1.1 Valid CSS!