There are several tools for detecting memory-related bugs in C
programs, such as memory leak
s or illegal array indices. These programs include Dmalloc, Efence, Njamd and many others. I've used dmalloc quite a bit recently, and it seems pretty good. See www.dmalloc.com. It doesn't slow the program too much or hog too much memory.
Njamd ("Not just another memory debugger") also looked promising, but I was unable to use it without recompiling the kernel, because my program allocated too many chunks of memory.