This project has moved and is read-only. For the latest updates, please go here.

V2.2.2 Finding Spurious Leaks

Feb 12, 2012 at 11:03 AM

I was using V2.1 and decided to upgrade to the latest V2.2.2.

My project is a VS2010 MFC dialog application plus I have a wxWidgets version obviously not using MFC. The core functions are the same and in the same library but the GUI is obviously different.

In the MFC version, V2.1 did not find any leaks but V2.2.2 found 108!  In the wxWidgets version, V2.1 found none and V2.2.2 found 4.  In fact, none of these leaks are actually leaks as I can prove that the memory for the class concerned is deleted.  The 4 come from just accessing the programs command line e.g.:

    f:\dd\vctools\crt_bld\self_x86\crt\src\ioinit.c (129): pwsafe.exe!_ioinit + 0x15 bytes
    f:\dd\vctools\crt_bld\self_x86\crt\src\crt0.c (248): pwsafe.exe!__tmainCRTStartup + 0x5 bytes
    f:\dd\vctools\crt_bld\self_x86\crt\src\crt0.c (189): pwsafe.exe!WinMainCRTStartup
    0x758C339A (File and line number not available): kernel32.dll!BaseThreadInitThunk + 0x12 bytes
    0x77299EF2 (File and line number not available): ntdll.dll!RtlInitializeExceptionChain + 0x63 bytes
    0x77299EC5 (File and line number not available): ntdll.dll!RtlInitializeExceptionChain + 0x36 bytes

The others that I can prove are spurious are caused by something like this:

Header file:

 

class A

{
public:
 static A *GetInstance();
 static void DeleteInstance();
private:
 static A *self;
 ...
};

Implementation file:

A *A::self = NULL;

A *A::GetInstance()
{
  if (self == NULL) {
    self = new A;
  }
  return self;
}

void A::DeleteInstance()
{
  delete self;
  self = NULL;
}

A::A()
{
  ...
}

A::~A()
{
}

The application always accesses this class via "A::GetInstance()->..." and on exiting calls "A::DeleteInstance();" yet VLS V2.2.2 states that all class A's variables have not been freed and seems to think that they have been reallocated many times when they are only allocated once in A::GetInstance().

Is this a known issue?

David

Feb 12, 2012 at 12:17 PM

Thank you for reporting. I'll try reproduce your issue.

Feb 12, 2012 at 12:30 PM

I cannot reproduce. You use static or dynamic CRT linking? What wxWidgets version you use?

Feb 12, 2012 at 12:43 PM

It is an Open Source project at SourceForge and we use static linking as we don't want to ship DLLs with our application.

The wxWidgets issue is evident in both 2.8.11 and 2.8.12 with VLD V2.2.2.  It is interesting that the 104 extra memory leaks are in the MFC code only even though both versions use the same underlying core functions and both call "A::GetInstance()->..." on startup and on exiting call "A::DeleteInstance();".  We do these type of calls (GetInstance and DeleteInstance) for a number of classes.

Feb 12, 2012 at 12:46 PM

Can you post full log to http://pastebin.com/ or somewhere else?

Feb 12, 2012 at 1:15 PM

See http://pwsafe.org/tmp/VLD_2.2.2.zip

Thx

Feb 12, 2012 at 1:34 PM

 BTW - VLD V2.1 reports no memory leaks in both instances.  No source code changes between tests - just using the appropriate version of vld.h etc.

Feb 12, 2012 at 2:07 PM

I compiled pwsafe DebugM - Win32. How can I reproduce bug?

Feb 12, 2012 at 2:22 PM

I have uploaded a test database to  http://pwsafe.org/tmp/Sample123.zip (note that, on this site, file names are case sensitive)  The passphrase is "123" without the quotes.

Just open the database and then exit (via menu File->Exit). 108 memory leaks.  class "PWSrand" is an example of class "A" I mentioned above.  Its source is in src/core directory.

PS. I added the "#include <vld.h>" in "ThisMfcApp.cpp".

Feb 12, 2012 at 11:29 PM

Fixed

Feb 12, 2012 at 11:43 PM

Thanks

Feb 13, 2012 at 10:01 PM

I have downloaded the source with the fix but, try as I might, I can't build a new version.

When using ...\vld\trunk\vld_vs10.sln I get a number of errors and the build fails - I suspect because I tried to build all. When I use ...\vld\trunk\setup\build_version.bat, it builds successfully but then says it fails and is aborted - probably because I do not have NSIS installed.

Would you mind building a version of the updated setup file for me to download please?

Feb 14, 2012 at 5:40 PM

Hi,

I have a very similar issue.

VLD v2.1 found 8 memory leaks in my project.

And, VLD v2.2.2 found 64 memory leaks.

Rob

Feb 14, 2012 at 7:36 PM

Belay my request. I downloaded NSIS and was easily able to build the new setup for VLD (it purports to be V2.2.3).

Tested and it fixes the issue.

Many thanks

Feb 14, 2012 at 10:06 PM
proengin wrote:

Hi,

I have a very similar issue.

VLD v2.1 found 8 memory leaks in my project.

And, VLD v2.2.2 found 64 memory leaks.

Rob

Please try version 2.2.3

Feb 14, 2012 at 10:45 PM
KindDragon wrote:
proengin wrote:

Hi,

I have a very similar issue.

VLD v2.1 found 8 memory leaks in my project.

And, VLD v2.2.2 found 64 memory leaks.

Rob

Please try version 2.2.3

Thanks.  v2.2.3 fixed the problem.

Rob