QT 内存泄漏检测工具VLD

1. 官方下载地址:https://kinddragon.github.io/vld/

可以下载最新的版本V2.5.1

2. 下载后安装。

3. VLD内存泄漏检测工具,只能检测MSVC类型编译器,不能用于检测MinGW编译器。

如果有安装VS,就会有MSVC编译器。

4.VLD内存泄漏检测工具的三种配置方式:

     第一种配置方式:

(1)复制VLD安装目录下include文件夹中的vld.h和vld_def.h到QT安装目录的include文件夹中。

(2)将“.../lib/Win64”或“.../lib/Win32”(位数根据QT安装位数确定)下的vld.lib拷贝到QT默认的lib目录。

     第二种配置方式:

修改.pro文件,添加如下内容:

//...为VLD的安装路径
win32{
    CONFIG(debug, debug|release) {
    INCLUDEPATH += .../VLD/include
    DEPENDPATH += .../VLD/include
    LIBS += -L.../VLD/lib/Win32 -lvld
    }
}

     第三种配置方式:

直接在main.cpp头部添加

#pragma comment(lib,".../VLD/lib/Win32/vld.lib")
#ifdef _DEBUG
#include ".../VLD/include/vld.h"
#endif

5. 使用时,需要在main.cpp中添加头文件即可。

#ifdef _DEBUG
#include "vld.h"
#endif

6. 若检测出漏洞,警告信息为:

WARNING: Visual Leak Detector detected memory leaks!
---------- Block 10 at 0x000000001634B820: 1 bytes ----------
  Leak Hash: 0x04EDF29C, Count: 1, Total 1 bytes
  Call Stack (TID 12832):
    ucrtbased.dll!malloc()
    d:\agent\_work\2\s\src\vctools\crt\vcstartup\src\heap\new_scalar.cpp (35): VLDTestProject1.exe!operator new() + 0xA bytes
    f:\vldtest\vldtestproject1\testwidget.cpp (6): VLDTestProject1.exe!TestWidget::TestWidget() + 0xA bytes

//------出现漏洞的代码位置--------------
    f:\vldtest\vldtestproject1\mainwindow.cpp (18): VLDTestProject1.exe!MainWindow::on_TestBtn_clicked() + 0x23 bytes
//------出现漏洞的代码位置--------------


    f:\vldtest\build-vldtestproject1-desktop_qt_5_9_4_msvc2017_64bit-debug\debug\moc_mainwindow.cpp (76): VLDTestProject1.exe!MainWindow::qt_static_metacall()
    f:\vldtest\build-vldtestproject1-desktop_qt_5_9_4_msvc2017_64bit-debug\debug\moc_mainwindow.cpp (105): VLDTestProject1.exe!MainWindow::qt_metacall()
    Qt5Cored.dll!QAssociativeIterable::const_iterator::~const_iterator() + 0x4A96C7 bytes
    Qt5Cored.dll!QAssociativeIterable::const_iterator::~const_iterator() + 0x4EE1E5 bytes
    Qt5Cored.dll!QAssociativeIterable::const_iterator::~const_iterator() + 0x4ED84B bytes
    Qt5Widgetsd.dll!QGraphicsEllipseItem::extension() + 0x28EDCA bytes
    Qt5Widgetsd.dll!QGraphicsEllipseItem::extension() + 0x290F01 bytes
    Qt5Widgetsd.dll!QGraphicsEllipseItem::extension() + 0x28FFC4 bytes
    Qt5Widgetsd.dll!QGraphicsEllipseItem::extension() + 0x28F584 bytes
    Qt5Widgetsd.dll!QGraphicsEllipseItem::extension() + 0xE53EA bytes
    Qt5Widgetsd.dll!QGraphicsEllipseItem::extension() + 0x28F018 bytes
    Qt5Widgetsd.dll!QGraphicsEllipseItem::extension() + 0x3AC0FE bytes
    Qt5Widgetsd.dll!QGraphicsEllipseItem::extension() + 0x8834B bytes
    Qt5Widgetsd.dll!QGraphicsEllipseItem::extension() + 0x83579 bytes
    Qt5Cored.dll!QAssociativeIterable::const_iterator::~const_iterator() + 0x49AFF9 bytes
    Qt5Cored.dll!QAssociativeIterable::const_iterator::~const_iterator() + 0x5FEDAE bytes
    Qt5Widgetsd.dll!QGraphicsEllipseItem::extension() + 0x8AA80 bytes
    Qt5Widgetsd.dll!QGraphicsEllipseItem::extension() + 0x130F83 bytes
    Qt5Widgetsd.dll!QGraphicsEllipseItem::extension() + 0x12F747 bytes
    Qt5Widgetsd.dll!QGraphicsEllipseItem::extension() + 0x8834B bytes
    Qt5Widgetsd.dll!QGraphicsEllipseItem::extension() + 0x82D70 bytes
    Qt5Cored.dll!QAssociativeIterable::const_iterator::~const_iterator() + 0x49AFF9 bytes
    Qt5Cored.dll!QAssociativeIterable::const_iterator::~const_iterator() + 0x5FEDAE bytes
    Qt5Guid.dll!QOpenGLFunctions_4_0_Compatibility::glSecondaryColor3uiv() + 0xD1C36 bytes
    Qt5Guid.dll!QOpenGLFunctions_4_0_Compatibility::glSecondaryColor3uiv() + 0xD481F bytes
    Qt5Guid.dll!QOpenGLFunctions_4_0_Compatibility::glSecondaryColor3uiv() + 0x8EDF1 bytes
    qwindowsd.dll!qt_plugin_query_metadata() + 0xC1FA2 bytes
    Qt5Cored.dll!QAssociativeIterable::const_iterator::~const_iterator() + 0x55358A bytes
    USER32.dll!DispatchMessageW() + 0x6A6 bytes
    USER32.dll!DispatchMessageW() + 0x1C2 bytes
    Qt5Cored.dll!QAssociativeIterable::const_iterator::~const_iterator() + 0x553FAE bytes
    qwindowsd.dll!qt_plugin_query_metadata() + 0xC1F54 bytes
    Qt5Cored.dll!QAssociativeIterable::const_iterator::~const_iterator() + 0x4953AB bytes
    Qt5Cored.dll!QAssociativeIterable::const_iterator::~const_iterator() + 0x4955F1 bytes
    Qt5Cored.dll!QAssociativeIterable::const_iterator::~const_iterator() + 0x498C22 bytes
    Qt5Guid.dll!QOpenGLFunctions_4_0_Compatibility::glSecondaryColor3uiv() + 0xCF184 bytes
    Qt5Widgetsd.dll!QGraphicsEllipseItem::extension() + 0x82877 bytes
    f:\vldtest\vldtestproject1\main.cpp (14): VLDTestProject1.exe!main() + 0x6 bytes
    c:\users\qt\work\qt\qtbase\src\winmain\qtmain_win.cpp (104): VLDTestProject1.exe!WinMain() + 0xE bytes
    d:\agent\_work\2\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl (107): VLDTestProject1.exe!invoke_main()
    d:\agent\_work\2\s\src\vctools\crt\vcstartu
p\src\startup\exe_common.inl (288): VLDTestProject1.exe!__scrt_common_main_seh() + 0x5 bytes
    d:\agent\_work\2\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl (331): VLDTestProject1.exe!__scrt_common_main()
    d:\agent\_work\2\s\src\vctools\crt\vcstartup\src\startup\exe_winmain.cpp (17): VLDTestProject1.exe!WinMainCRTStartup()
    KERNEL32.DLL!BaseThreadInitThunk() + 0x14 bytes
    ntdll.dll!RtlUserThreadStart() + 0x21 bytes
  Data:
    CD                                                           ........ ........

 

参考文章:https://www.cnblogs.com/chay/p/11526163.html

你可能感兴趣的:(QT)