开发者

Can you recommend a good debugging malloc library for linux?

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 abo开发者_如何转开发ut Valgrind, but sometimes the performance is really too low.


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


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

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


gcc now comes with sanitizers which are much more faster than valgrind. you can check different compiler options under -fsanitize. More info here


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>


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜