views:

145

answers:

4

Can you recommend a good debugging malloc library for linux? I know there are a lot of options out there, I just need to know which libraries people are actually using to solve real-life problems.

Thanks!

EDIT: I know about Valgrind, but sometimes the performance is really too low.

+4  A: 

Valgrind. :-) It's not a malloc library, but, it's really good at finding memory management and memory usage bugs.

Chris Jester-Young
+4  A: 

http://valgrind.org/ for finding memory leaks and heap corruption.

http://dmalloc.com/ for general purpose heap debugging.

nos
+1  A: 

This might not be very useful to you, but you could write your own malloc wrapper. In our special "diagnostic" builds it keeps a table of all outstanding allocations (including the file name and line number where the allocation occurred) and prints out anything that was still outstanding at exit time. It also uses canary words (to check for buffer overflows) and a combination of memory re-writing and block checksumming after free and before reallocation (to check for use-after-free).

If your product is sufficiently large it might be annoying to have to find-replace your entire source, hoping for the best. Also, the development time for your own malloc wrapper is probably not negligible. Doing lots of heavyweight stuff like what I mentioned above probably won't help out your speed problem, either. Writing your own wrapper would allow the most flexibility, though.

jdizzle
+2  A: 

The GNU C library itself has some debugging features and hooks you can use to add your own.

For documentation on a Linux system type info libc and then g Heap<TAB>. Another useful info node is "Hooks for Malloc", you can get there with g Hooks<TAB>

Zan Lynx
You could also link to the online manual: http://www.gnu.org/software/libc/manual/html_node/Heap-Consistency-Checking.html http://www.gnu.org/software/libc/manual/html_node/Hooks-for-Malloc.html
ephemient