欧美大屁股bbbbxxxx,狼人大香伊蕉国产www亚洲,男ji大巴进入女人的视频小说,男人把ji大巴放进女人免费视频,免费情侣作爱视频

歡迎來到入門教程網(wǎng)!

C語言

當(dāng)前位置:主頁 > 軟件編程 > C語言 >

Unix下C程序內(nèi)存泄漏檢測工具Valgrind的安裝與使用詳解

來源:本站原創(chuàng)|時間:2020-01-10|欄目:C語言|點擊: 次

Valgrind是一款用于內(nèi)存調(diào)試、內(nèi)存泄漏檢測以及性能分析的軟件開發(fā)工具。
Valgrind的最初作者是Julian Seward,他于2006年由于在開發(fā)Valgrind上的工作獲得了第二屆Google-O'Reilly開源代碼獎。
Valgrind遵守GNU通用公共許可證條款,是一款自由軟件。

官網(wǎng)
http://www.valgrind.org
 
下載與安裝
#wget http://www.valgrind.org/downloads/valgrind-3.8.1.tar.bz2
#tar xvf valgrind-3.8.1.tar.bz2
#cd valgrind-3.8.1
#./configure --prefix=/usr/local/webserver/valgrind
#make
#make install

測試代碼

復(fù)制代碼 代碼如下:

#include <stdlib.h>
int* func(void)
{
   int* x = malloc(10 * sizeof(int));
   x[10] = 0;  //問題1: 數(shù)組下標(biāo)越界
}                 
 int main(void)
{
   int* x=NULL;
   x=func();
   //free(x); 
   x=NULL;
   return 0;   //問題2: 內(nèi)存沒有釋放
 }

編譯
#gcc -g -o test test.c

內(nèi)存檢查
#valgrind --tool=memcheck --leak-check=yes --show-reachable=yes ./test

報告:


說明
Invalid write of size 4:表示數(shù)組越界寫了4字節(jié)
40 bytes in 1 blocks:表示因程序退出而發(fā)生內(nèi)存泄露40字節(jié)

修復(fù)bug,重新檢查提示已經(jīng)沒有內(nèi)存泄露



文檔:
Valgrind 中包含的 Memcheck 工具可以檢查以下的程序錯誤:

使用未初始化的內(nèi)存 (Use of uninitialised memory)
使用已經(jīng)釋放了的內(nèi)存 (Reading/writing memory after it has been free'd)
使用超過malloc分配的內(nèi)存空間(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申請和釋放內(nèi)存的匹配(Mismatched use of malloc/new/new [] vs free/delete/delete [])
src和dst的重疊(Overlapping src and dst pointers in memcpy() and related functions)
重復(fù)free

上一篇:C++運(yùn)算符重載 成員函數(shù)與友元函數(shù)詳解

欄    目:C語言

下一篇:淺析c#中WebBrowser控件的使用方法

本文標(biāo)題:Unix下C程序內(nèi)存泄漏檢測工具Valgrind的安裝與使用詳解

本文地址:http://mengdiqiu.com.cn/a1/Cyuyan/4244.html

網(wǎng)頁制作CMS教程網(wǎng)絡(luò)編程軟件編程腳本語言數(shù)據(jù)庫服務(wù)器

如果侵犯了您的權(quán)利,請與我們聯(lián)系,我們將在24小時內(nèi)進(jìn)行處理、任何非本站因素導(dǎo)致的法律后果,本站均不負(fù)任何責(zé)任。

聯(lián)系QQ:835971066 | 郵箱:835971066#qq.com(#換成@)

Copyright © 2002-2020 腳本教程網(wǎng) 版權(quán)所有