Debugging Memory Leaks

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi, <br/> <br/> Ive developed an unmanaged dll and a win 32 console application to test it (neither the dll nor the application use mfc or atl libraries). Now I am looking for memory leaks in the dll, so Ive added the following code to one of my classes inside it.<br/> <br/>
<div style="color:Black;background-color:White
<pre><span style="color:Blue #define
_CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>

<span style="color:Green // The code below was added to the class constructor:

_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
[/code]

<br/> The problem is that when I run my application I get the following output:<br/> <br/>
<pre>Detected memory leaks!
Dumping objects ->
{1600} normal block at 0x00D86928, 346 bytes long.
Data: < V > 00 00 01 56 00 04 00 00 00 00 00 00 00 00 FF 03
{1599} normal block at 0x00D867A8, 322 bytes long.
Data: < > > 00 00 01 3E 00 04 00 00 00 00 00 00 00 00 FF 03
{1557} normal block at 0x00BBE1A8, 302 bytes long.
Data: <FMR 20 . 5 > 46 4D 52 00 20 32 30 00 01 2E 00 35 0A 01 00 00
{1556} normal block at 0x00D61C30, 64 bytes long.
Data: < > 00 04 00 00 00 00 00 00 03 FF 00 00 00 00 00 00
{1555} normal block at 0x00BBD5E0, 278 bytes long.
Data: <FMR 20 5 > 46 4D 52 00 20 32 30 00 01 16 00 35 0A 01 00 00
{1554} normal block at 0x00D60770, 64 bytes long.
Data: < > 00 04 00 00 00 00 00 00 03 FF 00 00 00 00 00 00
{841} normal block at 0x00BBC998, 1710 bytes long.
Data: <t- 0ee4fa57-216> 74 5C 2D 10 30 65 65 34 66 61 35 37 2D 32 31 36
Object dump complete.[/code]
<br/> However since I have defined _CRTDBG_MAP_ALLOC I was expecting an output similar to the one below:<br/> <br/>
<pre>Detected memory leaks!
Dumping objects ->
D:VisualC++CodeGuruMemoryLeakMemoryLeak.cpp(67) : {60}
normal block at 0x00324818, 4 bytes long.
Data: <, > 2C 00 00 00
Object dump complete.[/code]
<br/> The strangest thing is that the output format that I am getting is expected when _CRTDBG_MAP_ALLOC is not defined.<br/> <br/> Then I made a small test program (code is below) to see if I could get the memory leak output correctly:<br/> <br/>
<div style="color:Black;background-color:White
<pre>#include <span style="color:#a31515 "stdafx.h"


<span style="color:Blue #define
_CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>

<span style="color:Blue int
_tmain(<span style="color:Blue int
argc, _TCHAR* argv[])
{

<span style="color:Blue int
*i = <span style="color:Blue new
<span style="color:Blue int
;
*i = 44;

_CrtDumpMemoryLeaks();
<span style="color:Blue return
0;
}


[/code]

<br/> However the output that I am receiving is still as if didnt defined _CRTDBG_MAP_ALLOC.<br/> <br/>
<pre>Detected memory leaks!
Dumping objects ->
{92} normal block at 0x00393778, 4 bytes long.
Data: <, > 2C 00 00 00
Object dump complete.
The program [3672] Teste.exe: Native has exited with code 0 (0x0).[/code]
<br/> How can I fix this output? What am I doing wrong?<br/> <br/> Thanks,<br/> Komyg<br/> <br/> <br/>

View the full article
 
Back
Top