squashed.bugaboo
squashed.bugaboo

Reputation: 1356

C++ Memory issues and diagnostics on Windows using MSVC++ 2005

I'm chasing a memory bug with a not so helpful diagnostic message:

HEAP[myprogram_run.exe]: HEAP: Free Heap block e0969b0 modified at e096a70 after it was freed
Windows has triggered a breakpoint in myprogram_run.exe.

This may be due to a corruption of the heap, and indicates a bug in myprogram_run.exe or any of 
the DLLs it has loaded.

The output window may have more diagnostic information
The program '[9340] myprogram_run.exe: Native' has exited with code -1 (0xffffffff).

After looking around, I found at these MSDN links: http://msdn.microsoft.com/en-US/library/e5ewb1h3%28v=vs.80%29 I set my Project Properties preprocessor definitions (under C/C++) to include _DEBUG and in my main function, I added the following in the order recommended as well (in link above):

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

...

int main(..,..) {
   ...
   _CrtDumpMemoryLeaks();
   return retval;
}

But I do not still see the advertised diagnostic output (incl. line numbers, etc.) in the Output windows of the Visual Studio solution? Appreciate any insight on how to go about diagnosing this correctly. Thanks!

that I could set under Project Properties

Upvotes: 1

Views: 325

Answers (1)

Jon Cage
Jon Cage

Reputation: 37458

Are you sure your code is reaching the _CrtDumpMemoryLeaks call before it crashes? My guess is your code is crashing out trying to free some already freed memory before it gets a chance to report any possible memory leaks.

Have a look at the Microsoft sample for more clues on how to use the debugging features.

Upvotes: 1

Related Questions