Valgrind使用说明
Valgrind manual:
http://valgrind.org/docs/manual/manual.html
Memcheck。这是valgrind应用最广泛的工具,一个重量级的内存检查器,能够发现开发中绝大多数内存错误使用情况,我们主要使用即此工具,默认选项。此工具检查下面的程序错误:
· 使用未初始化的内存 (Use of uninitialised memory)
· 使用已经释放了的内存 (Reading/writing memory after it has been free’d)
· 使用超过 malloc分配的内存空间(Reading/writing off the endof malloc’d blocks)
· 对堆栈的非法访问 (Reading/writing inappropriate areas on the stack)
· 申请的空间是否有释放 (Memory leaks – where pointers to malloc’d blocks are lost forever)
· malloc/free/new/delete申请和释放内存的匹配(Mismatched use of malloc/new/new [] vs free/delete/delete [])
· src和dst的重叠(Overlapping src and dst pointers inmemcpy() and related functions)
可以看出报告的基本格式是:
- 1
- 2
- 3
- 4
- 5
- 6
而报告的输出文档整体格式则可以总结为:
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
definitely lost:内存没有被释放,且没有任何指针指向这里。肯定泄漏了。报告给出的堆栈是内存被分配时的调用堆栈,它可以基本明确内存是由什么业务逻辑创建的。
still reachable:是说内存没有被释放,尽管如此仍有指针指向,内存仍在使用中,这可以不算泄露。(程序退出时仍在工作的异步系统调用?)
possibly lost:是说可能有泄漏,一般是有二级指针(指针的指针)等复杂情况不易于追踪时出现。
suppressed:统计了使用valgrind的某些参数取消了特定库的某些错误,会被归结到这里
参考网站:
http://www.linuxidc.com/Linux/2012-06/63754.htm
http://elinux.org/Valgrind (wiki)
http://blog.csdn.net/sduliulun/article/details/7732906
http://blog.csdn.net/gatieme/article/details/51959654(比较全面的介绍)
http://www.linuxidc.com/Linux/2012-06/63754.htm (非常详细的介绍了每个工具的使用)