首页 > 其他分享 >【Visual Leak Detector】在 VS 2015 中使用 VLD

【Visual Leak Detector】在 VS 2015 中使用 VLD

时间:2023-04-15 20:48:03浏览次数:43  
标签:exe Leak bytes VLD CD Visual Detector

说明

使用 VLD 内存泄漏检测工具辅助开发时整理的学习笔记。本篇介绍在 VS 2015 中使用 VLD。同系列文章目录可见 《内存泄漏检测工具》目录

目录


1. 使用前的准备

参考本人另一篇博客 安装 Visual Leak Detector 下载 vld-2.5.1-setup.exe 并按步骤安装 VLD。注意配置环境的时候一定要把三个选项都打上勾,在一台电脑上配置完成后,用的时候十分方便,包含头文件就可以使用,不需添加任何多余的代码。

3. 在 VS 2015 中使用 VLD

在项目的 main.cpp 文件中,添加头文件:

#include <vld.h>

选择 x86 或者 x64 编译器,选择 Debug 模式,编译运行,就可以正常使用了。我的 VS 版本是 Microsoft Visual Studio Professional 2015,VLD 安装目录为 D:\Program Files (x86)\Visual Leak Detector

3.1 无内存泄漏时的输出报告

程序运行结束后,若没有检测到内存泄漏,VLD 会输出以下 4 行报告:

Visual Leak Detector read settings from: D:\Program Files (x86)\Visual Leak Detector\vld.ini
Visual Leak Detector Version 2.5.1 installed.
No memory leaks detected.
Visual Leak Detector is now exiting.

3.2 有内存泄漏时的输出报告

程序运行结束后,若检测到内存泄漏,VLD 会输出以下报告(本例中出现一处内存泄漏,使用 x86 编译器):

Visual Leak Detector read settings from: D:\Program Files (x86)\Visual Leak Detector\vld.ini
Visual Leak Detector Version 2.5.1 installed.
WARNING: Visual Leak Detector detected memory leaks!
---------- Block 1 at 0x008D8980: 20 bytes ----------
  Leak Hash: 0xC3828EE7, Count: 1, Total 20 bytes
  Call Stack (TID 12948):
    f:\dd\vctools\crt\vcstartup\src\heap\new_array.cpp (15): testVLD.exe!operator new[]() + 0x9 bytes
    e:\cworkspace\vsdemo\testvld\testvld\main.cpp (8): testVLD.exe!main() + 0x7 bytes
    f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl (74): testVLD.exe!invoke_main() + 0x1B bytes
    f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl (264): testVLD.exe!__scrt_common_main_seh() + 0x5 bytes
    f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl (309): testVLD.exe!__scrt_common_main()
    f:\dd\vctools\crt\vcstartup\src\startup\exe_main.cpp (17): testVLD.exe!mainCRTStartup()
    KERNEL32.DLL!BaseThreadInitThunk() + 0x19 bytes
    ntdll.dll!__RtlUserThreadStart() + 0x2F bytes
    ntdll.dll!_RtlUserThreadStart() + 0x1B bytes
  Data:
    CD CD CD CD    CD CD CD CD    CD CD CD CD    CD CD CD CD     ........ ........
    CD CD CD CD                                                  ........ ........


Visual Leak Detector detected 1 memory leak (56 bytes).
Largest number used: 56 bytes.
Total allocations: 56 bytes.
Visual Leak Detector is now exiting.

若使用的是 x64 编译器,报告输出如下:

Visual Leak Detector read settings from: D:\Program Files (x86)\Visual Leak Detector\vld.ini
Visual Leak Detector Version 2.5.1 installed.
“testVLD.exe”(Win32): 已加载“C:\Windows\System32\kernel.appcore.dll”。已加载符号。
WARNING: Visual Leak Detector detected memory leaks!
---------- Block 1 at 0x00000000650C6AD0: 20 bytes ----------
  Leak Hash: 0x72624394, Count: 1, Total 20 bytes
  Call Stack (TID 12984):
    f:\dd\vctools\crt\vcstartup\src\heap\new_array.cpp (16): testVLD.exe!operator new[]()
    e:\cworkspace\vsdemo\testvld\testvld\main.cpp (8): testVLD.exe!main() + 0xA bytes
    f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl (75): testVLD.exe!invoke_main()
    f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl (264): testVLD.exe!__scrt_common_main_seh() + 0x5 bytes
    f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl (309): testVLD.exe!__scrt_common_main()
    f:\dd\vctools\crt\vcstartup\src\startup\exe_main.cpp (17): testVLD.exe!mainCRTStartup()
    KERNEL32.DLL!BaseThreadInitThunk() + 0x14 bytes
    ntdll.dll!RtlUserThreadStart() + 0x21 bytes
  Data:
    CD CD CD CD    CD CD CD CD    CD CD CD CD    CD CD CD CD     ........ ........
    CD CD CD CD                                                  ........ ........


Visual Leak Detector detected 1 memory leak (72 bytes).
Largest number used: 72 bytes.
Total allocations: 72 bytes.
Visual Leak Detector is now exiting.

4. 无法正常使用的可能原因

  • 检查是否是 Debug 模式,VLD 无法直接在 Release 模式下使用。
  • 检查环境变量是否正确配置,环境变量是 VLD 安装程序自动配置的,但是若在安装时没有勾选自动配置,会导致环境变量缺失,查看 Path 这一系统变量中是否添加了 VLD 的 bin 路径(我的是 D:\Program Files (x86)\Visual Leak Detector\bin\Win32D:\Program Files (x86)\Visual Leak Detector\bin\Win64 这两个)。
  • 在 VLD 安装成功后,是否已经重启了 VS,因为要加载 VLD 安装时新添的环境变量,若没重启 VS,可能找不到 VLD 的依赖环境。
  • 检查 includelib 目录是否被正确添加,这一步也是 VLD 安装程序自动进行的,打开项目属性页,点击 C/C++ -> 常规 -> 附加包含目录 查看是否添加了 VLD 的 include 目录(我的是 D:\Program Files (x86)\Visual Leak Detector\include),然后点击 链接器 -> 常规 -> 附加库目录 查看是否添加了 VLD 的 lib 目录(在我电脑上,使用 x86 编译器时是 D:\Program Files (x86)\Visual Leak Detector\lib\Win32,使用 x64 编译器时是 D:\Program Files (x86)\Visual Leak Detector\lib\Win64)。
  • 清除上一次的编译文件,重新编译运行一下。

标签:exe,Leak,bytes,VLD,CD,Visual,Detector
From: https://www.cnblogs.com/young520/p/17321794.html

相关文章

  • Eclipse 安装 ABAP 插件报错 Microsoft Visual C++ 2013 (x64) 快速解决
     去官网下载MicrosoftVisualC++2013(x64)安装   DownloadVisualC++RedistributablePackagesforVisualStudio2013fromOfficialMicrosoftDownloadCenter   ......
  • Visual Stadio 编译提示 The BaseOutputPath/OutputPath property is not set for pr
    完整的错误信息是:TheBaseOutputPath/OutputPathpropertyisnotsetforproject'xx.csproj'.PleasechecktomakesurethatyouhavespecifiedavalidcombinationofConfigurationandPlatformforthisproject.Configuration='Debug'Plat......
  • Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Bui
    https://zhuanlan.zhihu.com/p/471661231下载软件链接:https://pan.baidu.com/s/12hhCEKnjr2Qq-H3sHuQiXQ?pwd=6g0v提取码:6g0v安装退出虚拟环境,重新进入pip安装对应包......
  • Visualizing MuZero Models
    发表时间:2021文章要点:这篇文章主要想看看muzero里面的model具体学到了什么表征。通过PCA降维的方式,发现最开始编码状态的h函数学到的embedding和动态转移函数g学到的embedding并不统一,存在很大差异。因为muzero里面没有相关的loss来控制他俩一样。然后作者就提出两种loss来约......
  • MSBUILD : error MSB3428: Could not load the Visual C++ component "VCBuild.exe".
    完整报错信息:MSBUILD:errorMSB3428:CouldnotloadtheVisualC++component"VCBuild.exe".Tofixthis,1)installthe.NETFramework2.0SDK,2)installMicrosoftVisualStudio2005or3)addthelocationofthecomponenttothesystempathifit......
  • 【Visual Leak Detector】Release 模式下使用 VLD
    说明使用VLD内存泄漏检测工具辅助开发时整理的学习笔记。本篇介绍如何在Release模式下使用VLD。同系列文章目录可见《内存泄漏检测工具》目录目录说明1.思路概述2.在QT中实践1.思路概述要在RELEASE模式下使用VLD,必须在包含头文件vld.h前预先定义VLD_FORCE_E......
  • 对Docker容器进行取证 CSAW CTF 2022 DockREleakage
    题目信息这是一道非常简单的题目意思是在构建docker时,有些东西泄露了,需要我们在里面找到flag开始我们下载附件,然后解压压缩包tar-xvfdockREleakage.tar.gzx:提取v:显示所有过程f:指定文件这里有一些json文件,是docker构建时的核心文件,我们打开看看都是一行,读起来很不方便,我们格式化......
  • Visual Studio C盘数据迁移,解决C盘空间不足的问题
     迁移原理:将VisualStudio比较占用磁盘空间的“C:\ProgramFiles(x86)\MicrosoftSDKs\”目录和“C:\ProgramFiles(x86)\WindowsKits\”目录移动到D盘,然后通过mklink命令建立C盘和D盘的软连接然后在cmd下执行下面命令即可(如果提示C盘找不到目录,自己手动新建一个即可)......
  • Can't open dsw file in Visual Studio C++ 6.0
    Can'topendswfileinVisualStudioC++6.0 WhenItryto"OpenWorkplace"ofmyproject,visualstudiodoesnothing,solutionexplorerisempty.AlsowhenItrytoopenmyproject,Ioccasionallyseethiserror:Thismakefilewas......
  • Visual Studo for Mac 快捷键
    DefaultKeyboardShortcuts-VisualStudioforMac|MicrosoftLearnCodeNavigationCommandsKeyboardshortcutsFindReferences⇧⌘R, F12GotoDeclaration⌘D, F12NextError⌥⇧⇟, ⇧⌘F12NextIssueinFile⌥⇟PreviousError⌥⇧⇞......