How can I get valgrind to tell me the address of each non-freed block of memory?

风格不统一 提交于 2019-12-24 00:53:52

问题


Valgrind tells me function xxx allocated memory which was not freed. Fine. It's proving more difficult than usual to trace however.

To this end I have created numerous:

#ifdef DEBUG
fprintf(stderr, "something happening:%lx\n", (unsigned long)ptr);
#endif

So I just need to match these ptr addresses that are displayed with the addresses of non-freed memory.

How can I get valgrind to tell me the address of each non-freed block of memory?


回答1:


I don't believe Memcheck's leak checker supports printing addresses, unfortunately. This is due to the fact it's willing to merge multiple unallocated blocks into one "loss report" if they're similar.

If you don't mind poking around in Memcheck, this functionality should be abled to be added in memcheck/mc_leakcheck.c in the Valgrind source. I'll take a look at it when I get home and post a more detailed location.




回答2:


Thanks to Falaina for the code location.

For valgrind-3.2.3, location that worked for me was in memcheck/mc_leakcheck.c, lc_scan_memory_WRK function.

Added this after lc_markstack_push_WRK(addr, clique); on line # 472

if (clique != -1) { VG_(printf)("clique %d: %p\n", clique, ptr); }



来源:https://stackoverflow.com/questions/1540063/how-can-i-get-valgrind-to-tell-me-the-address-of-each-non-freed-block-of-memory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!