(VS15 C++) Got a Visual Leak Detector report, but what now?

2.1k Views Asked by At

because of some (strange) problems in my C++-project I used Visual Leak Detector (for the first time), to check the project on memory leaks. So I got i.a. the follwoing reports:

    WARNING: Visual Leak Detector detected memory leaks!
---------- Block 4 at 0x004D07B0: 200 bytes ----------
  Leak Hash: 0xD2D1B4A0, Count: 1, Total 200 bytes
  Call Stack (TID 8796):
    ucrtbase.dll!malloc()
    f:\dd\vctools\crt\vcstartup\src\heap\new_scalar.cpp (19): LASS.exe!operator new() + 0x8 bytes
    clr.dll!0x72D616E5()
  Data:
    28 75 14 03    00 00 00 00    01 00 00 00    00 00 00 00     (u...... ........
    9A 99 99 99    99 99 B9 3F    50 00 00 00    0A 00 00 00     .......? P.......
    00 00 00 00    F4 01 00 00    00 00 00 00    01 00 00 00     ........ ........
    7B 14 AE 47    E1 7A 74 3F    14 00 00 00    BA FF FF FF     {..G.zt? ........
    00 00 00 00    F4 01 00 00    00 00 00 00    01 00 00 00     ........ ........
    7B 14 AE 47    E1 7A 84 3F    00 00 00 00    64 00 00 00     {..G.z.? ....d...
    00 00 00 00    01 00 00 00    14 00 00 00    46 00 00 00     ........ ....F...
    00 00 00 00    64 00 00 00    00 00 00 00    F4 01 00 00     ....d... ........
    01 00 00 00    B8 E2 13 03    F0 AD 18 03    00 00 00 00     ........ ........
    C8 E2 13 03    C8 AB 18 03    00 00 00 00    78 E3 13 03     ........ ....x...
    B8 AC 18 03    00 00 00 00    68 E2 13 03    E8 AC 18 03     ........ h.......
    00 00 00 00    14 00 00 00    01 00 00 00    64 00 00 00     ........ ....d...
    01 00 00 00    00 00 00 00                                   ........ ........


---------- Block 20 at 0x004D0880: 200 bytes ----------
  Leak Hash: 0xD2D1B4A0, Count: 1, Total 200 bytes
  Call Stack (TID 8796):
    ucrtbase.dll!malloc()
    f:\dd\vctools\crt\vcstartup\src\heap\new_scalar.cpp (19): LASS.exe!operator new() + 0x8 bytes
    clr.dll!0x72D616E5()
  Data:
    78 74 14 03    00 00 00 00    01 00 00 00    00 00 00 00     xt...... ........
    9A 99 99 99    99 99 B9 3F    50 00 00 00    0A 00 00 00     .......? P.......
    00 00 00 00    F4 01 00 00    00 00 00 00    01 00 00 00     ........ ........
    7B 14 AE 47    E1 7A 74 3F    14 00 00 00    BA FF FF FF     {..G.zt? ........
    00 00 00 00    F4 01 00 00    00 00 00 00    01 00 00 00     ........ ........
    7B 14 AE 47    E1 7A 84 3F    00 00 00 00    64 00 00 00     {..G.z.? ....d...
    00 00 00 00    01 00 00 00    14 00 00 00    46 00 00 00     ........ ....F...
    00 00 00 00    64 00 00 00    00 00 00 00    F4 01 00 00     ....d... ........
    01 00 00 00    38 E2 13 03    00 F0 15 03    00 00 00 00     ....8... ........
    B8 E1 13 03    88 00 7F 05    00 00 00 00    08 E2 13 03     ........ ........
    20 FF 7E 05    00 00 00 00    E8 E1 13 03    80 FF 7E 05     ..~..... ......~.
    00 00 00 00    14 00 00 00    01 00 00 00    64 00 00 00     ........ ....d...
    01 00 00 00    00 00 00 00                                   ........ ........


---------- Block 31 at 0x0053E1B8: 72 bytes ----------
  Leak Hash: 0x3F88029B, Count: 1, Total 72 bytes
  Call Stack (TID 8796):
    ucrtbase.dll!malloc()
    f:\dd\vctools\crt\vcstartup\src\heap\new_scalar.cpp (19): LASS.exe!operator new() + 0x8 bytes
    clr.dll!0x72D616E5()
  Data:
    60 BC 55 00    40 3E 80 05    A0 3F 80 05    A0 3F 80 05     `.U.@>.. .?...?..
    60 BB 55 00    20 34 18 03    00 00 00 00    00 00 00 00     `.U..4.. ........
    00 00 00 00    20 00 00 00    2F 00 00 00    80 BC 55 00     ........ /.....U.
    00 2E 18 03    00 00 00 00    00 00 00 00    00 00 00 00     ........ ........
    20 00 00 00    2F 00 00 00                                   ..../... ........


---------- Block 33 at 0x0055BB60: 8 bytes ----------
  Leak Hash: 0xA49C5AA6, Count: 1, Total 8 bytes
  Call Stack (TID 8796):
    ucrtbase.dll!malloc()
    f:\dd\vctools\crt\vcstartup\src\heap\new_scalar.cpp (19): LASS.exe!operator new() + 0x8 bytes
    clr.dll!0x72D616E5()
  Data:
    C8 E1 53 00    00 00 00 00                               

   ..S..... ........

    //And many more...

Unfortunatly I do not understand, what VLD wants to say is the problem. With a double-click on the "f:\dd..."-lines it should set my courser to the line with the problem, shouldn´t it? But it dosen´t.

My question is now: How do I get to the area of the problem or in other words "how do I read these reports"?

In addition:

  • I use Visual Studio 2015
  • The project is a C++ Windows Forms Project
  • I included the vld.h in the additional includes and the lib-directory to the additional libraries of the project
  • In the main() I use #include <vld.h> and _CrtDumpMemoryLeaks();

EDIT:

My Main (a reduced version, but gives similar reports):

//some class-includes
#include <vld.h> 

using namespace System;
using namespace System::Windows::Forms;
using namespace std; 

#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>

[STAThread]
void Main()
{
    Application::EnableVisualStyles();
    Application::SetCompatibleTextRenderingDefault(false);


    Experiment* experiment = new Experiment();
    Experiment_List*  running_experiments = new Experiment_List(); 

    while(!experiment->end) {
        experiment= new Experiment();

        LASS::MainWindow form(experiment, running_experiments);
        form.ShowDialog();

        if(!experiment->end){
            running_experiments->register_experiment(experiment); 
        }
    }

    running_experimente->end_all(); 

    _CrtDumpMemoryLeaks();

    exit(0); 
}

Unfortunatley there are about 40 classes, that I do not want to post...

1

There are 1 best solutions below

1
Seboeh On

I don't know where the problem exact is. For me, it helps to run the program in RELEASE Mode, instead of DEBUG mode.

I suppose, my problem is the handling of managed and unmanaged code together. I have unmanaged code inside managed code. It seams as if CLR use a different new operator in Debug mode. Not as conform as the c++ standard.

According to: Using push_back() for STL List in C++ causes Access Violation, Crash

If you malloc() a C++ class, no constructors will be called for any of that class's fields

And the VS will step into a constructor in class new_scalar.cpp. Folks say that is depending of the Visual Leak Detector (VLD). You use them in your includes.

In the End, try to distinguish your code with

#pragma managed

and

#pragma unmanaged

And run in RELEASE mode.