Visual Leak Detector 在 VC++ 的 CRT 模块中报告奇怪的泄漏

Posted

技术标签:

【中文标题】Visual Leak Detector 在 VC++ 的 CRT 模块中报告奇怪的泄漏【英文标题】:Visual Leak Detector reporting strange leaks in CRT module of VC++ 【发布时间】:2015-08-28 11:25:57 【问题描述】:

我刚刚在 Windows 8 上安装了 Visual Leak Detector (2.3)。我用什么都不做的空白 CRT 程序(在 Visual Studio 2012 中)对其进行了测试。

#include <vld.h>

int main(int argc, char** argv) 

    return 0;

当我运行它时,VLD 报告 vc++ crt 模块中有奇怪的泄漏:

Visual Leak Detector Version 2.3 installed.
WARNING: Visual Leak Detector detected memory leaks!
---------- Block 31 at 0x0000000052C07530: 70 bytes ----------
  Call Stack:
    f:\dd\vctools\crt_bld\self_64_amd64\crt\src\stdenvp.c (127): my_application.exe!_setenvp + 0x27 bytes
    f:\dd\vctools\crt_bld\self_64_amd64\crt\src\crt0.c (223): my_application.exe!__tmainCRTStartup + 0x5 bytes
    f:\dd\vctools\crt_bld\self_64_amd64\crt\src\crt0.c (164): my_application.exe!mainCRTStartup
    0x00000000FAF8167E (File and line number not available): KERNEL32.DLL!BaseThreadInitThunk + 0x1A bytes
    0x00000000FD8CC3F1 (File and line number not available): ntdll.dll!RtlUserThreadStart + 0x21 bytes
  Data:
    20 B5 C0 52    50 00 00 00    50 92 C0 52    50 00 00 00     ...RP... P..RP...
    20 91 DD E1    F6 07 00 00    7E 00 00 00    02 00 00 00     ........ ~.......
    12 00 00 00    00 00 00 00    1F 00 00 00    FD FD FD FD     ........ ........
    50 52 4F 43    45 53 53 4F    52 5F 4C 45    56 45 4C 3D     PROCESSO R_LEVEL=
    36 00 FD FD    FD FD                                         6....... ........


---------- Block 40 at 0x0000000052C075D0: 72 bytes ----------
  Call Stack:
    f:\dd\vctools\crt_bld\self_64_amd64\crt\src\stdenvp.c (127): my_application.exe!_setenvp + 0x27 bytes
    f:\dd\vctools\crt_bld\self_64_amd64\crt\src\crt0.c (223): my_application.exe!__tmainCRTStartup + 0x5 bytes
    f:\dd\vctools\crt_bld\self_64_amd64\crt\src\crt0.c (164): my_application.exe!mainCRTStartup
    0x00000000FAF8167E (File and line number not available): KERNEL32.DLL!BaseThreadInitThunk + 0x1A bytes
    0x00000000FD8CC3F1 (File and line number not available): ntdll.dll!RtlUserThreadStart + 0x21 bytes
  Data:
    F0 94 C0 52    50 00 00 00    20 76 C0 52    50 00 00 00     ...RP... .v.RP...
    20 91 DD E1    F6 07 00 00    7E 00 00 00    02 00 00 00     ........ ~.......
    14 00 00 00    00 00 00 00    28 00 00 00    FD FD FD FD     ........ (.......
    53 45 53 53    49 4F 4E 4E    41 4D 45 3D    43 6F 6E 73     SESSIONN AME=Cons
    6F 6C 65 00    FD FD FD FD                                   ole..... ........


---------- Block 41 at 0x0000000052C07620: 67 bytes ----------
  Call Stack:
    f:\dd\vctools\crt_bld\self_64_amd64\crt\src\stdenvp.c (127): my_application.exe!_setenvp + 0x27 bytes
    f:\dd\vctools\crt_bld\self_64_amd64\crt\src\crt0.c (223): my_application.exe!__tmainCRTStartup + 0x5 bytes
    f:\dd\vctools\crt_bld\self_64_amd64\crt\src\crt0.c (164): my_application.exe!mainCRTStartup
    0x00000000FAF8167E (File and line number not available): KERNEL32.DLL!BaseThreadInitThunk + 0x1A bytes
    0x00000000FD8CC3F1 (File and line number not available): ntdll.dll!RtlUserThreadStart + 0x21 bytes
  Data:
    D0 75 C0 52    50 00 00 00    D0 96 C0 52    50 00 00 00     .u.RP... ...RP...
    20 91 DD E1    F6 07 00 00    7E 00 00 00    02 00 00 00     ........ ~.......
    0F 00 00 00    00 00 00 00    29 00 00 00    FD FD FD FD     ........ ).......
    53 79 73 74    65 6D 44 72    69 76 65 3D    43 3A 00 FD     SystemDr ive=C:..
    FD FD FD                                                     ........ ........


---------- Block 43 at 0x0000000052C07670: 65 bytes ----------
  Call Stack:
    f:\dd\vctools\crt_bld\self_64_amd64\crt\src\stdenvp.c (127): my_application.exe!_setenvp + 0x27 bytes
    f:\dd\vctools\crt_bld\self_64_amd64\crt\src\crt0.c (223): my_application.exe!__tmainCRTStartup + 0x5 bytes
    f:\dd\vctools\crt_bld\self_64_amd64\crt\src\crt0.c (164): my_application.exe!mainCRTStartup
    0x00000000FAF8167E (File and line number not available): KERNEL32.DLL!BaseThreadInitThunk + 0x1A bytes
    0x00000000FD8CC3F1 (File and line number not available): ntdll.dll!RtlUserThreadStart + 0x21 bytes
  Data:
    D0 96 C0 52    50 00 00 00    C0 76 C0 52    50 00 00 00     ...RP... .v.RP...
    20 91 DD E1    F6 07 00 00    7E 00 00 00    02 00 00 00     ........ ~.......
    0D 00 00 00    00 00 00 00    2B 00 00 00    FD FD FD FD     ........ +.......
    54 45 4D 50    3D 46 3A 5C    54 45 4D 50    00 FD FD FD     TEMP=F:\ TEMP....
    FD                                                           ........ ........


Visual Leak Detector detected 48 memory leaks (6044 bytes).
Largest number used: 15094 bytes.
Total allocations: 25276 bytes.
Visual Leak Detector is now exiting.

网上没有太多关于此的详细信息,但在thismsdn 论坛上有评论说:

与其说是真正的“泄漏”,不如说是“为你的环境做好准备” 执行'。它正在制作进程环境的可写副本 对于期望它的程序,它们将在 进程退出。您可以放心地忽略该报告。

但是,我想禁止这些行出现在报告中(如果它们真的不是泄漏)

有没有人遇到过这种情况并且知道如何解决?

【问题讨论】:

【参考方案1】:

最简单的解决方案显然是在 vld.ini 文件中添加 StartDisabled=yes ,然后从 main() 的第一行显式启用它。当然,您也会错过全局对象的“内存泄漏”,但这通常同样无害。

【讨论】:

谢谢!在某种程度上有效,但仍然出现了一些 CRT 泄漏。我发现这是我使用的 VLD 版本中的错误。【参考方案2】:

我发现这是 VLD 2.3 中的错误。错误的详细信息是here。我刚刚下载了 v2.4rc2 (vld-2.4rc2-setup.exe),这个问题似乎不再出现了。 (我已经下载了 v2.3,因为它已被标记为稳定)

【讨论】:

以上是关于Visual Leak Detector 在 VC++ 的 CRT 模块中报告奇怪的泄漏的主要内容,如果未能解决你的问题,请参考以下文章

Visual Leak Detector使用注意事项

Visual Leak Detector配置项 SkipCrtStartupLeaks

Visual Leak Detector简介

Visual Leak Detector 2 2 3 Visual C++内存检测工具

Visual Leak Detector 报告 qt 库泄漏

Visual Leak Detector配置项 VLD