BlueTune
BlueTune

Reputation: 1053

Locating a memory leak in the globals with given memory allocation number

I am trying to locate a memory leak in my c++ programm using VS 2019. The output in the Debug-Output window reads for example:

{3880} normal block at 0x00D66730, 8 bytes long.
 Data: < 5      > D8 35 0F 05 00 00 00 00

So the memory allocation number is 3880. In order to locate this leak I implemented a memory leak on purpose using a global variable:

#include "stdafx.h"
int* foo = DEBUG_NEW int;

This leads to an additional message:

C:\Main.cpp(5) : {3944} normal block at 0x00D24BF8, 4 bytes long.
 Data: <    > CD CD CD CD

So the memory allocation number 3880 is lower then memory allocation number of the on purpose memory leak (3944). Does this information allow me to draw the conclusion that the memory leak (with memory allocation number 3880) is due to a global variable? Or is it still possible, that it is a leak due to a DLL-file (or a global variable in a DLL-file)?

Upvotes: 0

Views: 542

Answers (1)

j6t
j6t

Reputation: 13582

You can add a Watch entry ucrtbased.dll!_crtBreakAlloc. It's initial value is -1. But you can set it to 3880 to request a stop at that allocation.

To get to that point when the allocation happens during startup is a bit difficult, though.

  1. You must set a function breakpoint at ucrtbased.dll!heap_alloc_dbg_internal.

  2. Run your program. It will stop at that function.

  3. Change the value of ucrtbased.dll!_crtBreakAlloc to 3880 (which you should have in your Watch window by now).

  4. Disable the breakpoint at heap_alloc_dbg_internal.

  5. Continue the program. Observe your program being halted at the requested allocation.

Upvotes: 1

Related Questions