我怎样才能让 valgrind 告诉我每个未释放的内存块的地址?
Valgrind 告诉我函数 xxx 分配了未释放的内存。美好的。然而事实证明,追踪比平常更困难。
为此我创建了许多:
#ifdef DEBUG
fprintf(stderr, "something happening:%lx\n", (unsigned long)ptr);
#endif
因此我只需要将显示的这些 ptr 地址与未释放内存的地址相匹配。
我怎样才能让 valgrind 告诉我每个未释放的内存块的地址?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不幸的是,我不相信 Memcheck 的泄漏检查器支持打印地址。这是因为如果多个未分配的块相似,它愿意将它们合并到一个“丢失报告”中。
如果您不介意在 Memcheck 中闲逛,那么应该能够在 Valgrind 源代码的 memcheck/mc_leakcheck.c 中添加此功能。我回家后会看一下并发布更详细的位置。
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.
感谢 Falaina 提供的代码位置。
对于 valgrind-3.2.3,对我有用的位置是 memcheck/mc_leakcheck.c 中的 lc_scan_memory_WRK 函数。
在 lc_markstack_push_WRK(addr, clique); 之后添加此内容第 472
行 if (clique != -1) { VG_(printf)("clique %d: %p\n", clique, ptr); }
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); }
十二年后,这一点仍然没有被添加。以下补丁是@Chaim 对 valgrind-3.18.1 的建议
Here we are twelve years later and this still hasn't been added. The following patch is @Chaim's suggestion to valgrind-3.18.1