Quantcast
Channel: Visual Leak Detector for Visual C++ 2008-2015
Viewing all 704 articles
Browse latest View live

Edited Unassigned: Stack overflow when VLD gets TLS slot >= 64 and allocate memory in new thread [10590]

$
0
0
In short, Stack overflow when VLD gets TLS slot >= 64 and allocate memory in new thread.

On Windows, by default Thread Local Storage (TLS) has 0x40 slots. Later it is expanded by 0x400 more slots. These expansion slots are created on demand when TLS APIs TlsAlloc/TlsFree/TlsGetValue/TlsSetValue are invoked in current thread. And the expansion is achieved by calling Windows API RtlAllocateHeap. When TLS APIs are invoked the first time with slot number >= 0x40 in a thread which hasn't expand before, TLS expansion will be triggered.

To assist troubleshooting memory leak issues, memory allocation APIs, including `RtlAllocateHeap`, are hooked by VLD.

When a memory allocation happens, VLD will store the information in its TLS slot to avoid contention and reduce performance impact. When VLD is assigned with a TLS slot >= 0x40 and a memory allocation happens in a thread that hasn't expand TLS, the access to TLS slot from VLD will trigger another TLS expansion.

However, the expansion will call `RtlAllocateHeap` to allocate memory and the record of this memory allocation will be saved into TLS slot by VLD, which will again trigger another TLS expansion... In this way, The program will enter infinite recursion.

The call stack of this crash will be looks like:

```
6dc9 0759f314 09ddbfcc 00000042 0a16b870 09defbd0 KERNELBASE!TlsSetValue+0x4f
6dca 0759f360 09ddc1a3 09defbd0 00490000 0759f38c vld!VisualLeakDetector::getTls+0xfc [c:\build\vld\v24c\src\vld.cpp @ 1075]
6dcb 0759f370 09dda74b 0baa5930 00000008 0759f69c vld!VisualLeakDetector::enabled+0x23 [c:\build\vld\v24c\src\vld.cpp @ 982]
6dcc 0759f38c 75c445cf 00490000 00000008 00001000 vld!VisualLeakDetector::_HeapAlloc+0x2b [c:\build\vld\v24c\src\vld_hooks.cpp @ 1617]
6dcd 0759f3a8 09ddbfcc 00000042 0a16b870 09defbd0 KERNELBASE!TlsSetValue+0x4f
6dce 0759f3f4 09ddc1a3 09defbd0 05480fe8 0759f420 vld!VisualLeakDetector::getTls+0xfc [c:\build\vld\v24c\src\vld.cpp @ 1075]
6dcf 0759f404 09dda74b 05480fd0 0000004c 0759f45c vld!VisualLeakDetector::enabled+0x23 [c:\build\vld\v24c\src\vld.cpp @ 982]
6dd0 0759f420 7614ea43 00490000 00000000 00000018 vld!VisualLeakDetector::_HeapAlloc+0x2b [c:\build\vld\v24c\src\vld_hooks.cpp @ 1617]
6dd1 0759f434 7614ea5f 762466bc 00000018 0759f450 ole32!CRetailMalloc_Alloc+0x16 [d:\w7rtm\com\ole32\com\class\memapi.cxx @ 641]
```

*To workaround this problem*, you can load VLD ASAP when application starts so it will get a TLS slot <64.

For a detailed explanation of Windows TLS internals, please refer to [Thread Local Storage, part 2: Explicit TLS](http://www.nynaeve.net/?p=181).

```
#include <windows.h>
#include <thread>
#include <chrono>
#include <memory>

int main(int argc, wchar_t *argv[]) {
for (int i = 0; i < 0x40; ++i)
TlsAlloc();

HMODULE h_vld = LoadLibraryA("vld.dll");
typedef void(*vld_enable_t)(void);
auto vld_enable = (vld_enable_t)::GetProcAddress(h_vld, "VLDGlobalEnable");
vld_enable();
std::thread([]() {std::make_shared<int>(); }).join();
return 0;
}
```

Created Unassigned: VLD not detecting memory leaks [10591]

$
0
0
This is the ouput I get:
```

No memory leaks detected.
Visual Leak Detector is now exiting.
Detected memory leaks!
Dumping objects ->
{4262} normal block at 0x00EA7A50, 13 bytes long.
Data: <*REDACTED* > 44 43 20 2D 20 44 43 20 2D 20 44 43 00
{4261} normal block at 0x00EA6CE8, 12 bytes long.
Data: <*REDACTED* > 44 43 20 46 49 54 54 49 5A 49 4F 00
{4260} normal block at 0x00EA67E0, 6 bytes long.
Data: <*REDACTED* > 41 6C 74 72 6F 00
{4259} normal block at 0x00EA6D58, 7 bytes long.
Data: <*REDACTED* > 42 61 63 6B 75 70 00
{4258} normal block at 0x00EA68F8, 10 bytes long.
Data: <*REDACTED* > 52 69 63 68 69 65 73 74 61 00
{4257} normal block at 0x00E7EDC8, 37 bytes long.
Data: <*REDACTED* > 54 72 6F 76 61 74 6F 20 64 75 70 6C 69 63 61 74
{4256} normal block at 0x00EADDD0, 4 bytes long.
Data: <*REDACTED* > 41 50 49 00
{4255} normal block at 0x00ECEA48, 78 bytes long.
Data: <*REDACTED* > 5B 56 45 52 42 43 4B 5D 20 56 65 72 69 66 69 63
{4254} normal block at 0x00EA7ED0, 18 bytes long.
Data: <*REDACTED* > 44 43 5F 42 4F 5F 50 72 65 73 69 64 69 6F 48 32
{4253} normal block at 0x00EA6BD0, 10 bytes long.
Data: <*REDACTED* > 43 52 45 41 5A 49 4F 4E 45 00
Object dump complete.
```

This is the command line:
```
/Yu"stdafx.h" /GS /analyze- /W3 /Zc:wchar_t /I"C:\Program Files (x86)\Visual Leak Detector\include" /ZI /Gm /Od /sdl /Fd"Debug\vc140.pdb" /Zc:inline /fp:precise /D "WIN32" /D "_WINDOWS" /D "_DEBUG" /D "_CRT_SECURE_NO_WARNINGS" /D "_UNICODE" /D "UNICODE" /D "_AFXDLL" /errorReport:prompt /WX- /Zc:forScope /RTC1 /Gd /Oy- /MDd /Fa"Debug\" /EHsc /nologo /Fo"Debug\" /Fp"Debug\*REDACTED*.pch
```

Commented Unassigned: VLD not detecting memory leaks [10591]

$
0
0
This is the ouput I get:
```

No memory leaks detected.
Visual Leak Detector is now exiting.
Detected memory leaks!
Dumping objects ->
{4262} normal block at 0x00EA7A50, 13 bytes long.
Data: <*REDACTED* > 44 43 20 2D 20 44 43 20 2D 20 44 43 00
{4261} normal block at 0x00EA6CE8, 12 bytes long.
Data: <*REDACTED* > 44 43 20 46 49 54 54 49 5A 49 4F 00
{4260} normal block at 0x00EA67E0, 6 bytes long.
Data: <*REDACTED* > 41 6C 74 72 6F 00
{4259} normal block at 0x00EA6D58, 7 bytes long.
Data: <*REDACTED* > 42 61 63 6B 75 70 00
{4258} normal block at 0x00EA68F8, 10 bytes long.
Data: <*REDACTED* > 52 69 63 68 69 65 73 74 61 00
{4257} normal block at 0x00E7EDC8, 37 bytes long.
Data: <*REDACTED* > 54 72 6F 76 61 74 6F 20 64 75 70 6C 69 63 61 74
{4256} normal block at 0x00EADDD0, 4 bytes long.
Data: <*REDACTED* > 41 50 49 00
{4255} normal block at 0x00ECEA48, 78 bytes long.
Data: <*REDACTED* > 5B 56 45 52 42 43 4B 5D 20 56 65 72 69 66 69 63
{4254} normal block at 0x00EA7ED0, 18 bytes long.
Data: <*REDACTED* > 44 43 5F 42 4F 5F 50 72 65 73 69 64 69 6F 48 32
{4253} normal block at 0x00EA6BD0, 10 bytes long.
Data: <*REDACTED* > 43 52 45 41 5A 49 4F 4E 45 00
Object dump complete.
```

This is the command line:
```
/Yu"stdafx.h" /GS /analyze- /W3 /Zc:wchar_t /I"C:\Program Files (x86)\Visual Leak Detector\include" /ZI /Gm /Od /sdl /Fd"Debug\vc140.pdb" /Zc:inline /fp:precise /D "WIN32" /D "_WINDOWS" /D "_DEBUG" /D "_CRT_SECURE_NO_WARNINGS" /D "_UNICODE" /D "UNICODE" /D "_AFXDLL" /errorReport:prompt /WX- /Zc:forScope /RTC1 /Gd /Oy- /MDd /Fa"Debug\" /EHsc /nologo /Fo"Debug\" /Fp"Debug\*REDACTED*.pch
```
Comments: CRT may report leaks where you doesn't have leaks. Are you sure that you have memory leak?

Closed Unassigned: Patch to support MFC 12 MBCS [10565]

$
0
0
I have a patch that provides support for the MBCS version of MFC 12 (mfc120.dll, mfc120d.dll).

New Post: VLD for Visual C++ 2015?

$
0
0
I just downloaded the sourcecode and compiled it with solution that was provided, not sure what SDK that I have that you guys don't.

When do you think you can have an beta (or alpha) installer for msvc 2015 online? We want to install it in our c++ computer labs at the university for the students to use.

Closed Unassigned: HeapDestroy without HeapFree really leaks memory? [10580]

$
0
0
Hi VLD developers, I'm a developer of [MinHook](http://www.example.com).

A user of MinHook reported a memory leak. In short, VLD reports a leak when calling HeapDestroy without HeapFree.
Look at the test code below:
```
#include <windows.h>
#include <vld.h>

int main()
{
HANDLE hHeap = HeapCreate(0, 0, 0);
LPVOID pHeap = HeapAlloc(hHeap, 0, 1024);

// Skip HeapFree intentionally.

HeapDestroy(hHeap); // returns TRUE

return 0;
}
```
It causes an error like this:
```
WARNING: Visual Leak Detector detected memory leaks!
---------- Block 1 at 0x010D05B8: 1024 bytes ----------
Call Stack:
d:\users\kageyu\documents\visual studio 2013\projects\heapleak\heapleak\main.cpp (10): HeapLeak.exe!main + 0x13 bytes
f:\dd\vctools\crt\crtw32\dllstuff\crtexe.c (626): HeapLeak.exe!__tmainCRTStartup + 0x19 bytes
f:\dd\vctools\crt\crtw32\dllstuff\crtexe.c (466): HeapLeak.exe!mainCRTStartup
0x748B7C04 (File and line number not available): KERNEL32.DLL!BaseThreadInitThunk + 0x24 bytes
0x76FFB90F (File and line number not available): ntdll.dll!RtlInitializeExceptionChain + 0x8F bytes
0x76FFB8DA (File and line number not available): ntdll.dll!RtlInitializeExceptionChain + 0x5A bytes
Data:
0D F0 AD BA 0D F0 AD BA 0D F0 AD BA 0D F0 AD BA ........ ........
0D F0 AD BA 0D F0 AD BA 0D F0 AD BA 0D F0 AD BA ........ ........
0D F0 AD BA 0D F0 AD BA 0D F0 AD BA 0D F0 AD BA ........ ........
0D F0 AD BA 0D F0 AD BA 0D F0 AD BA 0D F0 AD BA ........ ........
0D F0 AD BA 0D F0 AD BA 0D F0 AD BA 0D F0 AD BA ........ ........
0D F0 AD BA 0D F0 AD BA 0D F0 AD BA 0D F0 AD BA ........ ........
0D F0 AD BA 0D F0 AD BA 0D F0 AD BA 0D F0 AD BA ........ ........
0D F0 AD BA 0D F0 AD BA 0D F0 AD BA 0D F0 AD BA ........ ........
0D F0 AD BA 0D F0 AD BA 0D F0 AD BA 0D F0 AD BA ........ ........
0D F0 AD BA 0D F0 AD BA 0D F0 AD BA 0D F0 AD BA ........ ........
0D F0 AD BA 0D F0 AD BA 0D F0 AD BA 0D F0 AD BA ........ ........
0D F0 AD BA 0D F0 AD BA 0D F0 AD BA 0D F0 AD BA ........ ........
0D F0 AD BA 0D F0 AD BA 0D F0 AD BA 0D F0 AD BA ........ ........
0D F0 AD BA 0D F0 AD BA 0D F0 AD BA 0D F0 AD BA ........ ........
0D F0 AD BA 0D F0 AD BA 0D F0 AD BA 0D F0 AD BA ........ ........
0D F0 AD BA 0D F0 AD BA 0D F0 AD BA 0D F0 AD BA ........ ........


Visual Leak Detector detected 1 memory leak in heap 0x010D0000
```

However, according to the [HeapDestroy](http://msdn.microsoft.com/ja-jp/library/windows/desktop/aa366700%28v=vs.85%29.aspx) document:
> Processes can call HeapDestroy without first calling the HeapFree function to free memory allocated from the heap.


So I'm wondering if it is an actual memory leak or a false positive.

Closed Unassigned: VisualLeakDetector crashes while shutdown, process is terminated [10569]

$
0
0
The problem is that the functions which are hooked by VLD are not properly unhooked at VLD shutdown.
That means the hooked functions are called even though VLD is destroyed already and this leads to the crash.

In RestoreImport the hooked function GetProcAddress is used instead of the real GetProcAddress (_RGetProcAddress) function, so the replaced function pointers
are taken and not the original function pointers.

Comments: Should be fixed now

Commented Feature: Memory leaked from SysAllocString() is not detected [10218]

$
0
0
With these three lines allocating memory, only the first two are detected. The line that allocates memory using SysAllocString() does not show as leaked.

```
char* pst = new char[20];
BYTE* pb = (BYTE*) ::CoTaskMemAlloc(20);
BSTR bs = ::SysAllocString(L"hello");

```
Comments: Supported in develop branch

Source code checked in, #f7abad0b0a2a612203bcdbc4501247d4276a17cd

$
0
0
Fixed crash, when VLD is turned off through config

Source code checked in, #56baf1b735aedaf740537331f1c17efe86987995

$
0
0
Merge pull request #15 from akaStiX/master Fixed crash, when VLD is turned off through config

Source code checked in, #2e2dac90e7de8c99850fab70df8fcf07b5f1c7ca

Source code checked in, #c30f3c9202b92b89622c668aab6237f73b47ef53

$
0
0
Crash fixed dynamic_app test, Release, StackWalkMethod=safe; v140. Closes #17

Source code checked in, #8f5b0c2c042951f724160f34d07fc076dc14d67e

$
0
0
Simplify the CaptureContext constructor and remove the unnecessary context parameter

Source code checked in, #af71538309e694f1a61d396354bdea8072b23578

$
0
0
Test for "std::`dynamic initializer for '" false positive leak in Release_StaticCrt

Source code checked in, #a8c37d13de4ef3a3a33b6c058a63283f8d817cb3


Source code checked in, #bdae26bd9c641a48d97c24e62272a96c334d1ceb

Source code checked in, #5a08ef0c704821203b96f947d26763b3875eba56

$
0
0
Added Gitter notification: https://gitter.im/KindDragon/vld

Source code checked in, #09478143be9516eb32275a7feb7c338ae2717b83

$
0
0
Remove duplication of callstack resolve implementation in Callstack::dump

Created Unassigned: Visual Leak Detector not working with CppUnitTestFramework [10592]

$
0
0
Hi,

if I include the "vld.h" in a file and run unit test (with Microsofts CppUnitTestFramework) on the project
some problem occurs:

```
------ Discover test started ------
========== Discover test finished: 59 found (0:00:00,1930193) ==========
------ Run test started ------
The active Test Run was aborted because the execution process exited unexpectedly. Check the execution process logs for more information. If the logs are not enabled, then enable the logs and try again.
========== Run test finished: 0 run (0:00:01,9781978) ==========
```

If I "debug" the test case the test case runs after termination I see the following exceptions:

```
Visual Leak Detector: Waiting for threads to terminate...
No memory leaks detected.
First-chance exception at 0x000000001BCD7F2F (vld_x64.dll) in vstest.executionengine.exe: 0xC0000005: Access violation reading location 0xFFFFFFFFFFFFFFFF.
First-chance exception at 0x00000000777AEF39 (ntdll.dll) in vstest.executionengine.exe: 0xC0000005: Access violation reading location 0xFFFFFFFFFFFFFFFF.
First-chance exception at 0x00000000777AEF39 (ntdll.dll) in vstest.executionengine.exe: 0xC0000005: Access violation reading location 0xFFFFFFFFFFFFFFFF.
Unhandled exception at 0x00000000777AEF39 (ntdll.dll) in vstest.executionengine.exe: 0xC0000005: Access violation reading location 0xFFFFFFFFFFFFFFFF.
```


Googling this problem I found that others have similar problems, e.g.:
http://stackoverflow.com/questions/16232613/visual-leak-detector-not-working-with-unit-test-in-vs2012


Edited Unassigned: Visual Leak Detector not working with CppUnitTestFramework [10592]

$
0
0
Hi,

if I include the "vld.h" in a file and run unit test (with Microsofts CppUnitTestFramework) on the project
some problem occurs:

```
------ Discover test started ------
========== Discover test finished: 59 found (0:00:00,1930193) ==========
------ Run test started ------
The active Test Run was aborted because the execution process exited unexpectedly. Check the execution process logs for more information. If the logs are not enabled, then enable the logs and try again.
========== Run test finished: 0 run (0:00:01,9781978) ==========
```

If I "debug" the test case the test case runs after termination I see the following exceptions:

```
Visual Leak Detector: Waiting for threads to terminate...
No memory leaks detected.
First-chance exception at 0x000000001BCD7F2F (vld_x64.dll) in vstest.executionengine.exe: 0xC0000005: Access violation reading location 0xFFFFFFFFFFFFFFFF.
First-chance exception at 0x00000000777AEF39 (ntdll.dll) in vstest.executionengine.exe: 0xC0000005: Access violation reading location 0xFFFFFFFFFFFFFFFF.
First-chance exception at 0x00000000777AEF39 (ntdll.dll) in vstest.executionengine.exe: 0xC0000005: Access violation reading location 0xFFFFFFFFFFFFFFFF.
Unhandled exception at 0x00000000777AEF39 (ntdll.dll) in vstest.executionengine.exe: 0xC0000005: Access violation reading location 0xFFFFFFFFFFFFFFFF.
```


Googling this problem I found that others have similar problems, e.g.:
http://stackoverflow.com/questions/16232613/visual-leak-detector-not-working-with-unit-test-in-vs2012


I used VLD 2.4rc2.
Viewing all 704 articles
Browse latest View live