【Visual Leak Detector】配置项 SkipHeapFreeLeaks

说明

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

1. 配置文件使用说明

在程序中通过 #include "vld.h" 的方式检测内存泄漏时,VLD 首先会尝试在程序的生成目录下读取 vld.ini 文件,若未读取成功,则会尝试在 VLD 的安装目录下读取 vld.ini 文件,若仍未读取成功,则会使用内置的默认配置,内置的默认配置如果不动源码是无法更改的,因此通过修改相应目录下的 vld.ini 文件来定制 VLD 功能是最好的选择。当配置参数等号右边为空,或者给配置了不合法值时,在使用过程中会被程序重置到默认值。

2. 设置是否跳过堆内存泄漏检测

参数名SkipHeapFreeLeaks

有效赋值yesno

默认值no

功能说明文档原话Determines whether or not report memory leaks when missing HeapFree calls. 但是当我把这个变量设置为 yes 时仍可以检测到堆上的内存泄漏,这个配置项的实际作用有待进一步研究。

2.1 测试代码

#include <QCoreApplication>
#include "Windows.h"
#include "vld.h"

void testFun(int i)
{
    int *ptr = new int(i);
    printf("ptr = %08x, *ptr = %08x.\n", ptr, *ptr);

    int *pData= (int *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(int));
    printf("pData = %08x, *pData = %08x.\n", pData, *pData);
}

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    testFun(1);

    return a.exec();
}

测试环境:QT 5.9.2MSVC 2015 32bitDebug 模式,VLD 版本为 2.5.1,VLD 配置文件只对该参数做修改,测试工程所在路径为:E:\Cworkspace\Qt 5.9\QtDemo\testVLD

2.2 SkipHeapFreeLeaks = no 时的输出

标准输出窗显示:

ptr = 00539498, *ptr = 00000001.
pData = 00535720, *pData = 00000000.

VLD 输出报告:

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 2 at 0x00535720: 4 bytes ----------
  Leak Hash: 0x426C3DE0, Count: 1, Total 4 bytes
  Call Stack (TID 30052):
    ntdll.dll!RtlAllocateHeap()
    e:\cworkspace\qt 5.9\qtdemo\testvld\main.cpp (10): testVLD.exe!testFun() + 0x11 bytes
    e:\cworkspace\qt 5.9\qtdemo\testvld\main.cpp (18): 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!RtlGetAppContainerNamedObjectPath() + 0x11E bytes
    ntdll.dll!RtlGetAppContainerNamedObjectPath() + 0xEE bytes
  Data:
    00 00 00 00                                                  ........ ........


---------- Block 1 at 0x00539498: 4 bytes ----------
  Leak Hash: 0x19BB156F, Count: 1, Total 4 bytes
  Call Stack (TID 30052):
    ucrtbased.dll!malloc()
    f:\dd\vctools\crt\vcstartup\src\heap\new_scalar.cpp (19): testVLD.exe!operator new() + 0x9 bytes
    e:\cworkspace\qt 5.9\qtdemo\testvld\main.cpp (7): testVLD.exe!testFun() + 0x7 bytes
    e:\cworkspace\qt 5.9\qtdemo\testvld\main.cpp (18): 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!RtlGetAppContainerNamedObjectPath() + 0x11E bytes
    ntdll.dll!RtlGetAppContainerNamedObjectPath() + 0xEE bytes
  Data:
    01 00 00 00                                                  ........ ........


Visual Leak Detector detected 2 memory leaks (44 bytes).
Largest number used: 44 bytes.
Total allocations: 44 bytes.
Visual Leak Detector is now exiting.

2.3 SkipHeapFreeLeaks = yes 时的输出

标准输出窗显示:

ptr = 014e9450, *ptr = 00000001.
pData = 014e84b0, *pData = 00000000.

VLD 输出报告:

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 2 at 0x014E84B0: 4 bytes ----------
  Leak Hash: 0x7C37FF93, Count: 1, Total 4 bytes
  Call Stack (TID 7564):
    ntdll.dll!RtlAllocateHeap()
    e:\cworkspace\qt 5.9\qtdemo\testvld\main.cpp (10): testVLD.exe!testFun() + 0x11 bytes
    e:\cworkspace\qt 5.9\qtdemo\testvld\main.cpp (18): 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!RtlGetAppContainerNamedObjectPath() + 0x11E bytes
    ntdll.dll!RtlGetAppContainerNamedObjectPath() + 0xEE bytes
  Data:
    00 00 00 00                                                  ........ ........


---------- Block 1 at 0x014E9450: 4 bytes ----------
  Leak Hash: 0x8876C556, Count: 1, Total 4 bytes
  Call Stack (TID 7564):
    ucrtbased.dll!malloc()
    f:\dd\vctools\crt\vcstartup\src\heap\new_scalar.cpp (19): testVLD.exe!operator new() + 0x9 bytes
    e:\cworkspace\qt 5.9\qtdemo\testvld\main.cpp (7): testVLD.exe!testFun() + 0x7 bytes
    e:\cworkspace\qt 5.9\qtdemo\testvld\main.cpp (18): 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!RtlGetAppContainerNamedObjectPath() + 0x11E bytes
    ntdll.dll!RtlGetAppContainerNamedObjectPath() + 0xEE bytes
  Data:
    01 00 00 00                                                  ........ ........


Visual Leak Detector detected 2 memory leaks (44 bytes).
Largest number used: 44 bytes.
Total allocations: 44 bytes.
Visual Leak Detector is now exiting.

2.4 输出结果对比

SkipHeapFreeLeaks = noSkipHeapFreeLeaks = yes 的输出结果似乎没有什么实质性的差异,不过有一点需注意,使用 new 分配堆内存时,会额外添加 36 bytes 大小的内存用于追踪管理,但使用 HeapAlloc() 函数分配堆内存时,则没有额外的内存使用,因此上述测试例的 Total allocations44 bytes,而不是 80 bytes

原文链接:https://www.cnblogs.com/young520/p/17263228.html

本站文章如无特殊说明,均为本站原创,如若转载,请注明出处:【Visual Leak Detector】配置项 SkipHeapFreeLeaks - Python技术站

(0)
上一篇 2023年4月18日
下一篇 2023年4月18日

相关文章

  • C++/Qt网络通讯模块设计与实现(总结)

    至此,C++/Qt网络通讯模块设计与实现已分析完毕,代码已应用于实际产品中。 C++/Qt网络通讯模块设计与实现(一) 该章节从模块的功能需求以及非功能需求进行分析,即网络通讯模块负责网络数据包的发送、接收以及对外提供功能调用以及接口回调,其不进行产品业务的实现,达到平台化复用的目的,给出了类图,如下所示::   符合先设计再开发的思想,各类的功能也有详细描…

    C++ 2023年4月18日
    00
  • 【Visual Leak Detector】在 VS 2015 中使用 VLD

    说明 使用 VLD 内存泄漏检测工具辅助开发时整理的学习笔记。本篇介绍在 VS 2015 中使用 VLD。同系列文章目录可见 《内存泄漏检测工具》目录 目录 说明 1. 使用前的准备 3. 在 VS 2015 中使用 VLD 3.1 无内存泄漏时的输出报告 3.2 有内存泄漏时的输出报告 4. 无法正常使用的可能原因 1. 使用前的准备 参考本人另一篇博客 …

    C++ 2023年4月17日
    00
  • P6818 [PA2013]Działka 题解

    P6818 [PA2013]Działka 前言 我太菜了。。。。 对着 jiangly 大佬的题解研究了一下午研究了一下午才搞出来(泪目。 作为一个蒟蒻,我就详细的讲一下我对与本题的理解。 题意 本题的的题意描述的还是比较明了。 在二维坐标系中,输入 \(n\) 个点 \(m\) 次询问, 每次询问,给出一个矩阵, 求出矩阵内极大凸包的面积。 题解 1.如…

    C++ 2023年4月30日
    00
  • 前缀和

    前缀和 一、介绍 前缀,顾名思义就是一个东西前面的点缀…(bushi 其实打比方来说就是:假如有一字符串ABCD,那么他的前缀就是A、AB、ABC、ABCD这四个从新从第一个字母一次往后开始拼接的字符串。当然这是字符串。但前缀和一般应用于数组,对于给定的数组a=[1,2,3,4],他的前 i 项和sum[i]就表示数组中a[0]~a[i]的和,具体为:s…

    C++ 2023年5月3日
    00
  • 【Visual Leak Detector】核心源码剖析(VLD 2.5.1)

    说明 使用 VLD 内存泄漏检测工具辅助开发时整理的学习笔记。本篇对 VLD 2.5.1 源码做内存泄漏检测的思路进行剖析。同系列文章目录可见 《内存泄漏检测工具》目录 目录 说明 1. 源码获取 2. 源码文件概览 3. 源码剖析 3.1 通过 inline hook 修补 LdrpCallInitRoutine 3.2 通过 IAT hook 替换内存操…

    C++ 2023年5月11日
    00
  • 高效c语言1快速入门

    本章将开发你的第一个C语言程序:传统的 “Hello, world!”程序。然后讨论一些编辑器和编译器的选项,并阐述移植性问题。 Hello, world! #include <stdio.h> #include <stdlib.h> int main(void) { puts(“Hello, world!”); return EXI…

    C++ 2023年5月10日
    00
  • C++ 入门

    001 c++ 如何工作 任何以 # 开头的语句,都是预处理语句,所谓的预处理语句,在编译之前,就已经被处理了 关键字 include:找到 <> 文件(通常称为“头文件”),然后将 <> 中的所有内容拷贝到现在的文件里 main()比较特殊,虽然它的返回值类型是 int,但它不一定需要返回值,如果不设置返回值,默认返回 0 <…

    C++ 2023年5月11日
    00
  • XMake学习笔记(1):Windows(MSYS2)下MinGW-w64环境搭建和XMake安装

    以前写的C++基本都是C with STL,大多是面向过程的算法题,或者比较小的项目,然后经常报各种编译错误(对编译原理不熟),经常把人搞到崩溃,搞不懂构建、链接之类的东西。 现在开始记录一下XMake的学习笔记,记录一些学习过程中踩的坑,在这篇文章,你将学习到Windows下利用MSYS2进行Mingw-w64环境搭建和XMake安装,并用Xmake构建一…

    C++ 2023年4月30日
    00
合作推广
合作推广
分享本页
返回顶部