libmem(3)

NAME
libmem - memory checking library for C

DESCRIPTION
This is a simple memory handling shell for C, that aids the programmer in tracking down memory leakage.

It redefines malloc(), realloc(), strdup(), free() etc as macro calls that keep track of where each block was malloc()ed [it stores the filename and source lineno].

It redefines exit() to list out all blocks that have been malloc()d and not free(d) - for each block, it shows the size, the source filename and line no where the block was malloc()d.

There are also new functions you can call explicitly:

Mem_show(): display allocated memory chunks,

Mem_used(): find out how much memory is allocated,

Mem_check(): perform the "display and abort if any memory chunks are still allocated" check that the redefined exit() performs.

Developed from Dr Dobbs Journal, Annual C Issue, August 1990.

libmem is highly recommended! It is incredibly simple and useful.

USAGE
First install libmem into your TOOLDIR. Then to use libmem to check for memory leaks in any body of existing C code:

Edit all .c files and add '#include <mem.h>'

Edit the Makefile and put:

DEST = $(TOOLDIR)
LIBDIR = $(DEST)/lib/$(ARCH)
INCDIR = $(DEST)/include
CFLAGS = -I. -I$(INCDIR) -Wall -g
LDLIBS = -L$(LIBDIR) -lmem

Now 'make clean all' to do a complete rebuild.

Just run your program! If it exits and doesn't list out any malloc()d chunks, your program does not leak memory, or free invalid pointers.

PORTABILITY
LIBMEM should work fine on any system with a C compiler. If it doesn't, please let me know!

AUTHOR OF THIS VERSION
Duncan White, Dept of Computing, Imperial College London UK.
Email: d.white@imperial.ac.uk
(Original version: Dr Dobbs Journal, August 1990)