【LINUX】内存泄漏的排查(gdb及valgrind两种方式)

1.GDB方式

        1.1在gdb调试中,对有怀疑泄露的函数前后分别执行

call malloc_stats()

查看in use byte= 的数值变化,如果有增加,说明内存没有被释放。

2.使用valgrind工具

        2.1工具安装

        2.1.1从网站下载工具压缩包:

Valgrind: Current ReleasesOfficial Home Page for valgrind, a suite of tools for debugging and profiling. Automatically detect memory management and threading bugs, and perform detailed profiling. The current stable version is valgrind-3.19.0.https://valgrind.org/downloads/current.html#current

        2.1.2工具的安装

解压后,找到README文件,按照提示进行安装。

        2.2工具使用,参考如下文章链接 

valgrind --leak-check=yes myprog 

干货 | Linux系统下如何检测内存泄露?https://mp.weixin.qq.com/s/Zqnt0melfmBFIj_DhRYi8Q

3工具安装过程中的问题备忘

ubuntu安装valgrind,并进行简单程序的检查内存泄漏 - pjc的乖宝宝 - 博客园菜鸡模仿之路总是不那么顺利 1。首先官网http://valgrind.org/下载valgrind,解压 2。进入目录后 ./autogen.sh 好吧,我的电脑在这里就报错了 3。百度要装一个suhttps://www.cnblogs.com/stt-ac/p/11157220.html


版权声明:本文为guanlizhongxintishi原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。