如何让valgrind告诉我每个未释放的内存块的地址? [英] How can I get valgrind to tell me the address of each non-freed block of memory?

查看:106
本文介绍了如何让valgrind告诉我每个未释放的内存块的地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Valgrind告诉我函数xxx分配了未释放的内存.美好的.但是事实证明,这比平时要难得多.

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

为此,我创建了许多:

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

因此,我只需要将显示的这些ptr地址与未释放内存的地址进行匹配即可.

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

如何让valgrind告诉我每个未释放的内存块的地址?

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

推荐答案

感谢Falaina提供代码位置.

Thanks to Falaina for the code location.

对于valgrind-3.2.3,最适合我的位置是在memcheck/mc_leakcheck.c,lc_scan_memory_WRK函数中.

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

在lc_markstack_push_WRK(addr,clique)之后添加了此内容;在第472行上

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

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

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

这篇关于如何让valgrind告诉我每个未释放的内存块的地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆