使用工具 valgrind
工具安装
sudo apt-get install valgrind
运行并检测
以 helloworld 程序举例,运行命令行
valgrind --tool=memcheck --leak-check=full ./helloworld
内存泄露检查
当Log 有lost bytes 时,说明程序有内存泄露
LEAK SUMMARY:
definitely lost: 1 bytes in 2 blocks
indirectly lost: 35 bytes in 1 blocks
possibly lost: 0 bytes in 0 blocks
内存泄露代码定位
在日志里搜相应关键字,就能找到内存泄露点,本例在 case_write.c文件的68行。
C语言编码助手下载地址 v1.33 | |
win10 x64 版本下载 | ctestcode.cn/ctestcode_win10.zip |
linux x64 版本下载 | ctestcode.cn/ctestcode_linux_x64.zip |
编码助手加入了 <代码实验室>的功能