一、简单介绍
Valgrind是一款用于内存调试、内存泄漏检测以及性能分析的软件开发工具。
Valgrind的最初作者是Julian Seward,他于2006年由于在开发Valgrind上的工作获得了第二届Google-O'Reilly开源代码奖。
Valgrind遵守GNU通用公共许可证条款,是一款自由软件。
Website:http://www.valgrind.org
二、下载与安装
#wgethttp://www.valgrind.org/downloads/valgrind-3.8.1.tar.bz2
#tar -jxvf valgrind-3.8.1.tar.bz2
#cd valgrind-3.8.1
#./configure --prefix=/usr/local/webserver/valgrind
#make
#make install
三、使用方法
#include <stdlib.h>
int* func(void)
{
int* x = malloc(10 * sizeof(int));
x[10] = 0; //问题1: 数组下标越界
}
int main(void)
{
int* x=NULL;
x=func();
//free(x);
x=NULL;
return 0; //问题2: 内存没有释放
}
编译
#gcc -g -o test test.c
内存检查
#valgrind --tool=memcheck --leak-check=yes --show-reachable=yes ./test
报告:
说明
Invalid write of size 4:表示数组越界写了4字节
40 bytes in 1 blocks:表示因程序退出而发生内存泄露40字节
修复bug,重新检查提示已经没有内存泄露
Valgrind 中包含的 Memcheck 工具可以检查以下的程序错误:
使用未初始化的内存 (Use of uninitialised memory)
使用已经释放了的内存 (Reading/writing memory after it has been free’d)
使用超过malloc分配的内存空间(Reading/writing off the end of 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 in memcpy() and related functions)
重复free
四、其他参考
如果想进一步了解使用命令,可以参考:http://blog.csdn.net/luxiuwen/article/details/7659128
分享到:
相关推荐
linux平台下内存泄漏检测工具valgrind3.11
Linux C语言程序内存泄漏检测工具-Valgrind
arm环境内存泄漏检测工具valgrind,用于检测arm环境下的内存泄漏
介绍了使用内存泄漏检测工具valgrind的安装和使用,内附安装包,测试程序,使用说明文档。
以下是对Unix下C程序内存泄漏检测工具Valgrind的安装与使用进行了详细的分析介绍,需要的朋友可以过来参考下
在linux下使用内存检测工具valgrind对程序进行内存泄露检测及绘制函数调用关系。
valgrind 3.10.1 linux 进程内存检测工具 安装步骤: unzip valgrind-3.10.1.zip chmod 755 -R valgrind-3.10.1 cd valgrind-3.10.1 ./configure --prefix /opt/valgrind310 make make install valgrind就安装到了/...
Valgrind是一款用于内存调试、内存泄漏检测以及性能分析的软件开发工具。Valgrind这个名字取自北欧神话中英灵殿的入口。 Valgrind的最初作者是Julian Seward,他于2006年由于在开发Valgrind上的工作获得了第二届...
应用 Valgrind 发现 Linux 程序的内存问题,内存泄露,多次释放等的自动检测!
valgrind安装包 安装步骤 安装说明;以及一些检查内存泄漏的用法
valgrind安装与使用
valgrind是一款运行在linux下的,用来定位c/c++程序中内存使用方面的错误的工具,包括:内存泄漏、使用未初始化的内存、读/写已释放的内存、读/写内存越界、使用malloc/new/new[]和free/delete/delete[]不匹配,等等...
防止内存泄露 Linux下用Valgrind做检查 C语言
Linux 系统中valgrind检查内存泄露说明和安装包,只是简单的说明,使用方法说明中只是说明了一种检测内存泄漏问题的方法和语句
内存泄漏工具 使用命令例子,xxx为执行文件 可执行文件目录下执行: valgrind --leak-check=full --show-leak-kinds=all --log-file=log ./xxx 执行后的信息在log文件里。(路径:与exe相同)
应用-Valgrind-发现-Linux-程序的内存问题
valgrind源码 内存泄露 内存检测 工具
valgrind for android NDK, 由国外相关资源整理,并亲测试可用,只支持 arm 架构.