IDH - Yet another debug heap


What is IDH?

IDH is a debug heap for C/C++ on several platforms. It detects most overwrites, stale pointers, wild pointers, double-free and invalid mix of heap management functions.

Note

This is preliminary documentation

Description

For a description of the general technique behind IDH see my article in EDM/2. That article is about OS/2 but the technique is the same.

In general, I have ported the source code and tools to three flavours of *nix and three compilers. The logging format has changed a bit (no heap identification, 16 hex digits on 64-bit platforms, etc). I have improved the deallocation a bit. Instead of never reusing memory the heap will reuse memory but on a FIFO order, so it is unlikely that stale pointers will go undetected.

IDH has been tested with:

Download

Download source here: idh-19.tar-gz (14KB)

History

How to use

Locate the makefile for your platform/compiler combination. For instance, Makefile_sparc_sws is for Solaris+SPARC+SunWorkshop. Simply type make -f Makefile_sparc_sws First you should try out the three sample programs to ensure that IDH most likely will work for your too. All three sample programs (idhtest1, idhtest2 and idhtest3) will crash inside strcpy(). If not, something is wrong.

Then try out leakfind and heapstat if you like.

If all the above succeeds you should be ready to use it in you own program. All you have to do is include idh.o callpeek.o and callpeek_cpp.o in the linker line. Make sure that you include -lpthread too (this also applies to sun workshop!). Start you program and wait for the coredump, or investigate the memory leaks afterwards.

Gotcha: Under LinuxThreads when forking you may see a single heaplog line from the child process ending up in the main heaplog (the caller is __pthread_reset_main_thread()). This will confuse leakfind and heapstat. There is no workaround (except editing the heaplog by hand)

Other relevant links

There is more tools like this, each with its own strengths and weaknesses. An (incomplete) list goes here:

A page at mpatrol has a very good link page to other tools.

Reverse links for the sites who are kind enough to provide links to this page: