实验第三方的内存泄露检测工具VLD(Visual Leak Detector)

[ 转载请注明来自CoderJeff的CSDN博客:http://blog.csdn.net/coderjeff/article/details/46474955,谢谢!]


VLD版本:2.2.3

VLD的安装目录:C:\Program Files (x86)\Visual Leak Detector

C++编译器:visual studio 2013

实验代码:

#include "stdafx.h"
#include  
#include


void func()

{
int *p = new int;  //第46行
}


int _tmain(int argc, _TCHAR* argv[])
{
int *p = new int[4];  //第56行
func();

return 0;
}


按照官方网站上的说法,在vs工程中设置好VLD的include和lib路径,包含上头文件,一切就绪,运行程序,但却接连出现错误。


1. 提示找不到vld_x86.dll文件。

解决方法:从VLD目录下,找到该文件,拷贝到程序的执行目录下。


2. 又提示”应用程序无法正常启动(0xc0150002)“。

解决方法:参考文章中的方法,在VLD目录中,找到Microsoft.DTfW.DHL.manifest,拷贝到程序的执行目录下。


3.又提示缺文件”dbghelp.dll“。

解决方法:在VLD目录中,找到该文件,拷贝到程序的执行目录下。


4.都没问题了,但运行结果却说没有检测到内存泄露:

Visual Leak Detector Version 2.2.3 installed.

No memory leaks detected.

Visual Leak Detector is now exiting.


在这个链接里找到了答案:在vs2013中确实不好使,只适用于vs2008/2010/2012。

解决方法:用VLD的新版本v2.4rc2


卸载掉2.2.3,在同一个位置安装2.4rc2,注意安装的时候会提示你先关闭vs。


别急着打开vs运行程序,否则,还会提示没有检测到内存泄露,控制台依然显示是2.2.3。需要把新版本的dbghelp.dll,vld_x86.dll,Microsoft.DTfW.DHL.manifest这三个文件拷贝到程序的执行目录下。


终于成功了!


下面是按F5后在output中的结果:


---------- Block 1 at 0x00550A20: 16 bytes ----------
  Leak Hash: 0x32782EB5, Count: 1, Total 16 bytes
  Call Stack (TID 11420):
    0x0F8DC260 (File and line number not available): MSVCR120D.dll!operator new
    f:\dd\vctools\crt\crtw32\stdcpp\newaop.cpp (6): ConsoleApplication3.exe!operator new[] + 0x9 bytes
    d:\programs\consoleapplication3\consoleapplication3\consoleapplication3.cpp (56): ConsoleApplication3.exe!wmain + 0x7 bytes
    f:\dd\vctools\crt\crtw32\dllstuff\crtexe.c (623): ConsoleApplication3.exe!__tmainCRTStartup + 0x19 bytes
    f:\dd\vctools\crt\crtw32\dllstuff\crtexe.c (466): ConsoleApplication3.exe!wmainCRTStartup
    0x76CB337A (File and line number not available): kernel32.dll!BaseThreadInitThunk + 0x12 bytes
    0x773292E2 (File and line number not available): ntdll.dll!RtlInitializeExceptionChain + 0x63 bytes
    0x773292B5 (File and line number not available): ntdll.dll!RtlInitializeExceptionChain + 0x36 bytes
  Data:
    CD CD CD CD    CD CD CD CD    CD CD CD CD    CD CD CD CD     ........ ........


---------- Block 2 at 0x00550A70: 4 bytes ----------
  Leak Hash: 0x5B08DF93, Count: 1, Total 4 bytes
  Call Stack (TID 11420):
    0x0F8DC260 (File and line number not available): MSVCR120D.dll!operator new
    d:\programs\consoleapplication3\consoleapplication3\consoleapplication3.cpp (46): ConsoleApplication3.exe!func + 0x7 bytes
    d:\programs\consoleapplication3\consoleapplication3\consoleapplication3.cpp (59): ConsoleApplication3.exe!wmain
    f:\dd\vctools\crt\crtw32\dllstuff\crtexe.c (623): ConsoleApplication3.exe!__tmainCRTStartup + 0x19 bytes
    f:\dd\vctools\crt\crtw32\dllstuff\crtexe.c (466): ConsoleApplication3.exe!wmainCRTStartup
    0x76CB337A (File and line number not available): kernel32.dll!BaseThreadInitThunk + 0x12 bytes
    0x773292E2 (File and line number not available): ntdll.dll!RtlInitializeExceptionChain + 0x63 bytes
    0x773292B5 (File and line number not available): ntdll.dll!RtlInitializeExceptionChain + 0x36 bytes
  Data:
    CD CD CD CD                                                  ........ ........


Visual Leak Detector detected 2 memory leaks (92 bytes).
Largest number used: 92 bytes.
Total allocations: 92 bytes.
Visual Leak Detector is now exiting.
The program '[11552] ConsoleApplication3.exe' has exited with code 0 (0x0).




你可能感兴趣的:(实验第三方的内存泄露检测工具VLD(Visual Leak Detector))