代码内存泄露检测工具(linux gcc + valrind)
2024-09-08 10:07:28
linux命令如下:valgrind --tool=memcheck --leak-check=full ./a.out
若没有valgrind工具,ubuntu下需要sudo apt-get install valgrind
如下:
举例说明:
#include <iostream>
using namespace std; int main(int argc, char *argv[])
{
string* s = new string("hello world");
cout<<*s<<endl; int* m = new int();
cout<<*m<<endl; delete m; return ;
} //running:
nol@nol-VirtualBox:~/desktop$ valgrind --tool=memcheck --leak-check=full ./a.out
==== Memcheck, a memory error detector
==== Copyright (C) -, and GNU GPL'd, by Julian Seward et al.
==== Using Valgrind-3.11. and LibVEX; rerun with -h for copyright info
==== Command: ./a.out
====
hello world ====
==== HEAP SUMMARY:
==== in use at exit: , bytes in blocks
==== total heap usage: allocs, frees, , bytes allocated
====
==== bytes in blocks are definitely lost in loss record of
==== at 0x4C2E0EF: operator new(unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==== by 0x400C40: main (in /home/nol/desktop/a.out)
====
==== LEAK SUMMARY:
==== definitely lost: bytes in blocks
==== indirectly lost: bytes in blocks
==== possibly lost: bytes in blocks
==== still reachable: , bytes in blocks
==== suppressed: bytes in blocks
==== Reachable blocks (those to which a pointer was found) are not shown.
==== To see them, rerun with: --leak-check=full --show-leak-kinds=all
====
==== For counts of detected and suppressed errors, rerun with: -v
==== ERROR SUMMARY: errors from contexts (suppressed: from )
nol@nol-VirtualBox:~/desktop$
最新文章
- DLL导出函数和类的定义区别 __declspec(dllexport)
- cookie小析
- Codeforces Round #172 (Div. 2)
- 如何在CALayer设置滤镜
- SQLite使用方法 SQLiteOpenHelper操作(转)
- freeCodeCamp:Missing letters
- 国产CPU研究单位及现状
- CF 567C Geometric Progression
- dotnet webservice处理数据量过大,ajax请求返回500错误解决方案
- MongoDb 快速入门教程
- mysql优化 | 存储引擎,建表,索引,sql的优化建议
- 第十五节 JS面向对象实例及高级
- C++中关于字符串的一些API
- ipfs webui 管理界面
- spring 配置文件的头部 xmls
- C++复习:继承与派生
- burpsuite的使用(一)
- 【cs229-Lecture10】特征选择
- [py][mx]django-解决注册用户已存在,激活链接判断
- HDU 2544:最短路