7

Closed

Static CRT leaks?

description

I use Visual Studio 2012 and VLD 2.2.3.
Compile option /MTd.
Memory leak is reported with the next code.
int _tmain(int argc, _TCHAR* argv[])
{
    return 0;
}
VisualLeakDetector::_HeapCreate() dose not seem to be called...

*I use machine translation, I cannot express it well.

file attachments

Closed Dec 22, 2013 at 8:52 PM by KindDragon
Commit 367d5721978b2b67ac02947a7140daf2e8ffef72

comments

zerochen wrote Sep 11, 2012 at 2:28 PM

same here with win7 & visual studio 2012 ultimate

i got 62 leaks like this

---------- Block 68 at 0x005A1640: 54 bytes ----------
Call Stack:
f:\dd\vctools\crt_bld\self_x86\crt\src\stdenvp.c (127): test.exe!_setenvp + 0x14 bytes <-- files dosent exist
f:\dd\vctools\crt_bld\self_x86\crt\src\crt0.c (223): test.exe!__tmainCRTStartup + 0x5 bytes
f:\dd\vctools\crt_bld\self_x86\crt\src\crt0.c (164): test.exe!mainCRTStartup
0x75C7339A (File and line number not available): kernel32.dll!BaseThreadInitThunk + 0x12 bytes
0x77039EF2 (File and line number not available): ntdll.dll!RtlInitializeExceptionChain + 0x63 bytes
0x77039EC5 (File and line number not available): ntdll.dll!RtlInitializeExceptionChain + 0x36 bytes
Data:
D8 15 5A 00    80 16 5A 00    30 F3 0C 00    7E 00 00 00     ..Z...Z. 0...~...
12 00 00 00    02 00 00 00    44 00 00 00    FD FD FD FD     ........ D.......
77 69 6E 64    69 72 3D 43    3A 5C 57 69    6E 64 6F 77     windir=C :\Window
73 00 FD FD    FD FD                                                        s....... ........

faburaya wrote Nov 16, 2012 at 12:33 AM

I have the same problem. I am running a command line application using googletest in Windows 8 Pro + Visual Studio 2012.

---------- Block 16 at 0x000000001C330080: 78 bytes ----------
Call Stack:
f:\dd\vctools\crt_bld\self_64_amd64\crt\src\stdenvp.c (127): Unit Tests.exe!_wsetenvp + 0x27 bytes
f:\dd\vctools\crt_bld\self_64_amd64\crt\src\crt0.c (223): Unit Tests.exe!__tmainCRTStartup + 0x5 bytes
f:\dd\vctools\crt_bld\self_64_amd64\crt\src\crt0.c (164): Unit Tests.exe!wmainCRTStartup
0x0000000062DA167E (File and line number not available): KERNEL32.DLL!BaseThreadInitThunk + 0x1A bytes
0x0000000065083501 (File and line number not available): ntdll.dll!RtlUserThreadStart + 0x21 bytes
Data:
B0 03 34 1C    ED 00 00 00    20 F7 33 1C    ED 00 00 00     ..4..... ..3.....
F8 2B DD 01    F6 07 00 00    7E 00 00 00    02 00 00 00     .+...... ~.......
1A 00 00 00    00 00 00 00    10 00 00 00    FD FD FD FD     ........ ........
48 00 4F 00    4D 00 45 00    44 00 52 00    49 00 56 00     H.O.M.E. D.R.I.V.
45 00 3D 00    43 00 3A 00    00 00 FD FD    FD FD           E.=.C.:. ........

---------- Block 33 at 0x000000001C3302C0: 76 bytes ----------
Call Stack:
f:\dd\vctools\crt_bld\self_64_amd64\crt\src\stdenvp.c (127): Unit Tests.exe!_wsetenvp + 0x27 bytes
f:\dd\vctools\crt_bld\self_64_amd64\crt\src\crt0.c (223): Unit Tests.exe!__tmainCRTStartup + 0x5 bytes
f:\dd\vctools\crt_bld\self_64_amd64\crt\src\crt0.c (164): Unit Tests.exe!wmainCRTStartup
0x0000000062DA167E (File and line number not available): KERNEL32.DLL!BaseThreadInitThunk + 0x1A bytes
0x0000000065083501 (File and line number not available): ntdll.dll!RtlUserThreadStart + 0x21 bytes
Data:
D0 11 34 1C    ED 00 00 00    50 12 34 1C    ED 00 00 00     ..4..... P.4.....
F8 2B DD 01    F6 07 00 00    7E 00 00 00    02 00 00 00     .+...... ~.......
18 00 00 00    00 00 00 00    21 00 00 00    FD FD FD FD     ........ !.......
50 00 52 00    4F 00 4D 00    50 00 54 00    3D 00 24 00     P.R.O.M. P.T.=.$.
50 00 24 00    47 00 00 00    FD FD FD FD                    P.$.G... ........

---------- Block 37 at 0x000000001C330380: 82 bytes ----------
Call Stack:
f:\dd\vctools\crt_bld\self_64_amd64\crt\src\stdenvp.c (127): Unit Tests.exe!_wsetenvp + 0x27 bytes
f:\dd\vctools\crt_bld\self_64_amd64\crt\src\crt0.c (223): Unit Tests.exe!__tmainCRTStartup + 0x5 bytes
f:\dd\vctools\crt_bld\self_64_amd64\crt\src\crt0.c (164): Unit Tests.exe!wmainCRTStartup
0x0000000062DA167E (File and line number not available): KERNEL32.DLL!BaseThreadInitThunk + 0x1A bytes
0x0000000065083501 (File and line number not available): ntdll.dll!RtlUserThreadStart + 0x21 bytes
Data:
90 F7 33 1C    ED 00 00 00    10 FB 33 1C    ED 00 00 00     ..3..... ..3.....
F8 2B DD 01    F6 07 00 00    7E 00 00 00    02 00 00 00     .+...... ~.......
1E 00 00 00    00 00 00 00    25 00 00 00    FD FD FD FD     ........ %.......
53 00 79 00    73 00 74 00    65 00 6D 00    44 00 72 00     S.y.s.t. e.m.D.r.
69 00 76 00    65 00 3D 00    43 00 3A 00    00 00 FD FD     i.v.e.=. C.:.....
FD FD                                                        ........ ........

---------- Block 43 at 0x000000001C3304A0: 84 bytes ----------
Call Stack:
f:\dd\vctools\crt_bld\self_64_amd64\crt\src\stdenvp.c (127): Unit Tests.exe!_wsetenvp + 0x27 bytes
f:\dd\vctools\crt_bld\self_64_amd64\crt\src\crt0.c (223): Unit Tests.exe!__tmainCRTStartup + 0x5 bytes
f:\dd\vctools\crt_bld\self_64_amd64\crt\src\crt0.c (164): Unit Tests.exe!wmainCRTStartup
0x0000000062DA167E (File and line number not available): KERNEL32.DLL!BaseThreadInitThunk + 0x1A bytes
0x0000000065083501 (File and line number not available): ntdll.dll!RtlUserThreadStart + 0x21 bytes
Data:
30 14 34 1C    ED 00 00 00    B0 14 34 1C    ED 00 00 00     0.4..... ..4.....
F8 2B DD 01    F6 07 00 00    7E 00 00 00    02 00 00 00     .+...... ~.......
20 00 00 00    00 00 00 00    2B 00 00 00    FD FD FD FD     ........ +.......
55 00 53 00    45 00 52 00    4E 00 41 00    4D 00 45 00     U.S.E.R. N.A.M.E.
3D 00 46 00    65 00 6C 00    69 00 70 00    65 00 00 00     =.F.e.l. i.p.e...
FD FD FD FD                                                  ........ ........

---------- Block 21 at 0x000000001C330A40: 80 bytes ----------
Call Stack:
f:\dd\vctools\crt_bld\self_64_amd64\crt\src\stdenvp.c (127): Unit Tests.exe!_wsetenvp + 0x27 bytes
f:\dd\vctools\crt_bld\self_64_amd64\crt\src\crt0.c (223): Unit Tests.exe!__tmainCRTStartup + 0x5 bytes
f:\dd\vctools\crt_bld\self_64_amd64\crt\src\crt0.c (164): Unit Tests.exe!wmainCRTStartup
0x0000000062DA167E (File and line number not available): KERNEL32.DLL!BaseThreadInitThunk + 0x1A bytes
0x0000000065083501 (File and line number not available): ntdll.dll!RtlUserThreadStart + 0x21 bytes
Data:
30 FA 33 1C    ED 00 00 00    60 05 34 1C    ED 00 00 00     0.3..... `.4.....
F8 2B DD 01    F6 07 00 00    7E 00 00 00    02 00 00 00     .+...... ~.......
1C 00 00 00    00 00 00 00    15 00 00 00    FD FD FD FD     ........ ........
4F 00 53 00    3D 00 57 00    69 00 6E 00    64 00 6F 00     O.S.=.W. i.n.d.o.
77 00 73 00    5F 00 4E 00    54 00 00 00    FD FD FD FD     w.s._.N. T.......

---------- Block 46 at 0x000000001C330CE0: 88 bytes ----------
Call Stack:
f:\dd\vctools\crt_bld\self_64_amd64\crt\src\stdenvp.c (127): Unit Tests.exe!_wsetenvp + 0x27 bytes
f:\dd\vctools\crt_bld\self_64_amd64\crt\src\crt0.c (223): Unit Tests.exe!__tmainCRTStartup + 0x5 bytes
f:\dd\vctools\crt_bld\self_64_amd64\crt\src\crt0.c (164): Unit Tests.exe!wmainCRTStartup
0x0000000062DA167E (File and line number not available): KERNEL32.DLL!BaseThreadInitThunk + 0x1A bytes
0x0000000065083501 (File and line number not available): ntdll.dll!RtlUserThreadStart + 0x21 bytes
Data:
30 15 34 1C    ED 00 00 00    50 26 34 1C    ED 00 00 00     0.4..... P&4.....
F8 2B DD 01    F6 07 00 00    7E 00 00 00    02 00 00 00     .+...... ~.......
24 00 00 00    00 00 00 00    2E 00 00 00    FD FD FD FD     $....... ........
77 00 69 00    6E 00 64 00    69 00 72 00    3D 00 43 00     w.i.n.d. i.r.=.C.
3A 00 5C 00    57 00 69 00    6E 00 64 00    6F 00 77 00     :.\.W.i. n.d.o.w.
73 00 00 00    FD FD FD FD                                   s....... ........

---------- Block 3 at 0x000000001C33F6B0: 98 bytes ----------
Call Stack:
f:\dd\vctools\crt_bld\self_64_amd64\crt\src\stdargv.c (142): Unit Tests.exe!_wsetargv + 0x2B bytes
f:\dd\vctools\crt_bld\self_64_amd64\crt\src\crt0.c (221): Unit Tests.exe!__tmainCRTStartup + 0x5 bytes
f:\dd\vctools\crt_bld\self_64_amd64\crt\src\crt0.c (164): Unit Tests.exe!wmainCRTStartup
0x0000000062DA167E (File and line number not available): KERNEL32.DLL!BaseThreadInitThunk + 0x1A bytes
0x0000000065083501 (File and line number not available): ntdll.dll!RtlUserThreadStart + 0x21 bytes
Data:
00 00 00 00    00 00 00 00    30 2A 34 1C    ED 00 00 00     ........ 0*4.....
C0 2B DD 01    F6 07 00 00    8E 00 00 00    02 00 00 00     .+...... ........
2E 00 00 00    00 00 00 00    03 00 00 00    FD FD FD FD     ........ ........
F0 F6 33 1C    ED 00 00 00    00 00 00 00    00 00 00 00     ..3..... ........
55 00 6E 00    69 00 74 00    20 00 54 00    65 00 73 00     U.n.i.t. ..T.e.s.
74 00 73 00    2E 00 65 00    78 00 65 00    00 00 FD FD     t.s...e. x.e.....
FD FD                                                        ........ ........
and more leaks....

proengin wrote Feb 12, 2013 at 2:21 PM

Hi,

I am having the same problem.
Did you ever find a solution?

Thanks.

mathieu_anthoine wrote Feb 21, 2013 at 9:36 AM

Same problem.
Win 7 x64
Visual studio 2012 premium

~60 leaks like the previous comment

ihenriksen wrote Jul 17, 2013 at 12:12 AM

Same problem here, an empty console application created with Visual Studio 2012 Update 3 has 57 internal memory leaks according to Visual Leak Detector.

griffwk wrote Dec 12, 2013 at 8:40 PM

Same here---

Is this a VisualLeakDetector problem or is this the CRT???

I can believe the CRT leaks, but WHY doesn't VLD have a way to "screen out" these reports? if they're known, then just give us an .INI entry to automatically ignore faults of this type...

OR is it that VLD exits before the CRT cleans up?

skorczyl wrote Dec 15, 2013 at 6:37 PM

I have managed to slightly debug the root cause of this problem with Visual Studio 2012 and Windows 7.
It reproduces with Visual Studio 2012 (v110) platform toolset and Multi-threaded Debug (/MTd) option only (static CRT).
It works (ie. no CRT leaks in the output) when setting either Multi-threaded Debug DLL (/MDd) option or Visual Studio 2010 (v100) platform toolset.
When comparing what is happening inside vld code I can see that with the 2010 platform toolset VLD is setting the VLD_HEAP_CRT_DBG flag in _HeapCreate function because it is called from the _heap_init CRT function. This function calls HeapCreate which is captured by VLD.
With the 2012 toolset the _heap_init CRT function does not call the HeapCreate API, but instead it uses GetProcessHeap() to get the process heap. And in this case VLD never sets the VLD_HEAP_CRT_DBG flag and outputs the CRT leaks.
So somehow VLD would need to better distinguish which heap or call is coming from the CRT.
I am using VLD v2.3.0.

Also I believe this is a duplicate of https://vld.codeplex.com/workitem/10421

skorczyl wrote Dec 22, 2013 at 8:11 PM

I confirm with the 367d5721978b patch the CRT leaks are no longer improperly reported.
Thank you very much!

KindDragon wrote Dec 30, 2013 at 10:18 AM

Thank you skorczyl for help with bug