Linux启动检测内存条错误,linux检测程序内存泄漏和内存错误

在linux的开发程序的时候,可以很方便的使用valgrind这个工具方便检测内存泄漏和内存错误。

安装很方便:

debian(如ubuntu)

sudo apt-get install valgrind

redhate系列(如centos)

sudo yum install valgrind

使用示例:

检测内存泄漏,

valgrind –leak-check=yes [application]

[application]就是你的程序名子。

输出结果如下:

==3122==

==3122== HEAP SUMMARY:

==3122==     in use at exit: 2,030 bytes in 6 blocks

==3122==   total heap usage: 25 allocs, 19 frees, 38,386,319 bytes allocated

==3122==

==3122== 583 bytes in 1 blocks are definitely lost in loss record 5 of 6

==3122==    at 0x4C2AC27: operator new[](unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)

==3122==    by 0x40335C: Performance_AES_CBC(char const*, char const*, unsigned int) (in /home/liyi/Study/c_c++/ipptest/bin/main)

==3122==    by 0x403ED6: PerformanceTest() (in /home/liyi/Study/c_c++/ipptest/bin/main)

==3122==    by 0x401834: main (in /home/liyi/Study/c_c++/ipptest/bin/main)

==3122==

==3122== LEAK SUMMARY:

==3122==    definitely lost: 583 bytes in 1 blocks

==3122==    indirectly lost: 0 bytes in 0 blocks

==3122==      possibly lost: 0 bytes in 0 blocks

==3122==    still reachable: 1,447 bytes in 5 blocks

==3122==         suppressed: 0 bytes in 0 blocks

==3122== Reachable blocks (those to which a pointer was found) are not shown.

==3122== To see them, rerun with: –leak-check=full –show-reachable=yes

==3122==

==3122== For counts of detected and suppressed errors, rerun with: -v

==3122== Use –track-origins=yes to see where uninitialised values come from

==3122== ERROR SUMMARY: 7 errors from 7 contexts (suppressed: 2 from 2)

使用

–leak-check=full –show-reachable=yes

可以查看更加详细的内存信息。

更多的信息参看valgrind官方文档,

http://valgrind.org/docs/manual/quick-start.html#quick-start.intro

版权所有,禁止转载. 如需转载,请先征得博主的同意,并且表明文章出处,否则按侵权处理.

分享到:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值