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

Visual Leak Detector reporting strange leaks in CRT module of VC++

我刚刚在 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.

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

That's not really a 'leak' so much as 'preparing your environment for execution'. It's making a writable copy of the process's environment for programs which expect it, and they will be released when the process exits. You can safely ignore the report.

但是,我想抑制这些行使其不出现在报告中(如果它们确实不是泄漏)

有没有人遇到过这种情况,知道怎么解决?

最简单的解决方案显然是在 vld.ini 文件中添加 StartDisabled=yes,然后从 main() 的第一行明确启用它。当然,您也会从全局对象中遗漏 "memory leaks",但这通常同样无害。

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