Checker

 [image of the Head of a GNU]

The GNU checker package has been decommissioned, as valgrind does a better job and is being actively maintained. Old home page preserved below for archeologists.


Checker is a tool which finds memory errors at runtime. Its primary function is to emit a warning when the program reads an uninitialized variable or memory area, or when the program accesses an unallocated memory area.

The Malloc library of Checker is very robust, though a bit slower than the usual GNU Malloc. Checker issues warnings when:

Checker's Malloc will refrain from reusing a freed block immediately; reuse of the block is delayed for some additional number of calls to free. This is to catch accesses to the block shortly after it has been freed.

Checker implements a garbage detector that can be called either in your program, by a debugger such as GDB, or on exit from the program. The garbage detector displays all the memory leaks along with the functions that called malloc.

Example

Here's a bogus file example.c:
  #include <stdlib.h>

  int
  main ()
  {
    char *zone = malloc (20);
    char *ptr = NULL;
    int i;
    char c;

    c = zone[1];     /* error: read an uninitialized char */
    c = zone[-2];    /* error: read before the zone */
    zone[25] = ' ';  /* error: write after the zone */
    *ptr = 2;	     /* error: use a NULL pointer,
                        must produce a core */
  }
To compile this example with Checker, simply use checkergcc instead of gcc:
% checkergcc -o example example.c
Next, to run the example:
  % ./example
Execution produces these warnings:
Checker 0.9 (sparc-sun-solaris2.5.1) Copyright (C) 1998 Tristan Gingold.
Checker is a memory access detector.
Checker is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
General Public License for more details.
For more information, set CHECKEROPTS to `--help'
From Checker (pid:04713): `./example' is running (Sun Jan 18 14:56:49 1998)

From Checker (pid:04713): (ruh) read uninitialized byte(s) in a block.
When Reading 1 byte(s) at address 0x000398a1, inside the heap (sbrk).
1 bytes into a block (start: 0x398a0, length: 20, mdesc: 0x0).
The block was allocated from:
	pc=0x00022f1c in chkr_malloc at ../stubs/stubs-malloc.c:51
	pc=0x0001339c in main at ../example.c:7
	pc=0x000155f0 in startup at ../config/sparc/solaris2/startup.c:148
	pc=0x00013298 in *unknown* at *unknown*:0
Stack frames are:
	pc=0x000133f4 in main at ../example.c:12
	pc=0x000155f0 in startup at ../config/sparc/solaris2/startup.c:148
	pc=0x00013298 in *unknown* at *unknown*:0
From Checker (pid:04713): (bvh) block bounds violation in the heap.
When Reading 1 byte(s) at address 0x0003989e, inside the heap (sbrk).
2 bytes before a block (start: 0x398a0, length: 20, mdesc: 0x0).
The block was allocated from:
	pc=0x00022f1c in chkr_malloc at ../stubs/stubs-malloc.c:51
	pc=0x0001339c in main at ../example.c:7
	pc=0x000155f0 in startup at ../config/sparc/solaris2/startup.c:148
	pc=0x00013298 in *unknown* at *unknown*:0
Stack frames are:
	pc=0x00013434 in main at ../example.c:13
	pc=0x000155f0 in startup at ../config/sparc/solaris2/startup.c:148
	pc=0x00013298 in *unknown* at *unknown*:0
From Checker (pid:04713): (bvh) block bounds violation in the heap.
When Writing 1 byte(s) at address 0x000398b9, inside the heap (sbrk).
5 bytes after a block (start: 0x398a0, length: 20, mdesc: 0x0).
The block was allocated from:
	pc=0x00022f1c in chkr_malloc at ../stubs/stubs-malloc.c:51
	pc=0x0001339c in main at ../example.c:7
	pc=0x000155f0 in startup at ../config/sparc/solaris2/startup.c:148
	pc=0x00013298 in *unknown* at *unknown*:0
Stack frames are:
	pc=0x0001345c in main at ../example.c:14
	pc=0x000155f0 in startup at ../config/sparc/solaris2/startup.c:148
	pc=0x00013298 in *unknown* at *unknown*:0
From Checker (pid:04713): (nza) null zone addressed.
When Writing 1 byte(s) at address 0x00000000, inside the NULL zone.
You probably deferenced a null pointer.
THIS SHOULD CAUSE A SEGMENTATION FAULT.
Stack frames are:
	pc=0x0001347c in main at ../example.c:15
	pc=0x000155f0 in startup at ../config/sparc/solaris2/startup.c:148
	pc=0x00013298 in *unknown* at *unknown*:0
From Checker (pid:04713): (sig) signal.
Receive signal 11 (SEGV): (default action: terminate core ).

Segmentation fault

Current status

At this time, the current version, 0.9.4, is available on alpha.gnu.org/gnu/. It has been ported to You need gcc-2.8.1 to use Checker.

Return to GNU's home page.

Please send FSF & GNU inquiries & questions to gnu@gnu.org. There are also other ways to contact the FSF.

Please send comments on these web pages to webmasters@www.gnu.org, send other questions to gnu@gnu.org.

Copyright © 1998, 2001, 2006 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA

Verbatim copying and distribution of this entire article is permitted in any medium, provided this notice is preserved.

Updated: $Date: 2006/11/20 09:38:32 $ $Author: ramprasadb $