Memory Debug Codes

Microsoft's memory management functions often initialize memory with special values. The following article describes frequent used variants.

Microsoft Visual C++ Runtime library

C runtime library provides it own debug codes:

0xCD, 0xCDCDCDCD - New objects. New objects are filled with 0xCD when they are allocated.
0xFD, 0xFDFDFDFD - No-man's land memory. Extra bytes that belong to the internal block allocated, but not the block you requested. They are placed before and after requested blocks and used for data bound checking.
0xDD, 0xDDDDDDDD - Freed blocks. The freed blocks kept unused in the debug heap's linked list when the _CRTDBG_DELAY_FREE_MEM_DF flag is set are currently filled with 0xDD. Although in some cases you won't see magic 0xDDDDDDDD value, as it will be overwritten by another debug function (e.g. 0xFEEEFEEE for HeapFree).

These constants are defined in DbgHeap.c file as

static unsigned char _bNoMansLandFill = 0xFD; /* fill no-man's land with this */
static unsigned char _bDeadLandFill = 0xDD; /* fill free objects with this */
static unsigned char _bCleanLandFill = 0xCD; /* fill new objects with this */

Compiler initialisations

0xCC, 0xCCCCCCCC - The /GX Microsoft Visual C++ compiler option initialises all local variables not explicitly initialised by the program. It fills all memory used by these variables with 0xCC, 0xCCCCCCCC.

Windows NT memory codes

0xABABABAB - Memory following a block allocated by LocalAlloc().
0xBAADF00D - "Bad Food". This is memory allocated via LocalAlloc( LMEM_FIXED, ... ). It is memory that has been allocated but not yet written to.
0xFEEEFEEE - OS fill heap memory, which was marked for usage, but wasn't allocated by HeapAlloc() or LocalAlloc(). Or that memory just has been freed by HeapFree().

Thanks to Samuel R. Blackburn, especially for Windows NT codes

Revision:1, Last Modified: 05/14/01 18:07, by Vadim Melnik. Visit my Homepage.

How to create ReleaseDebug configuration for Microsoft Visual C++ 6.0 projects?

It�s good style to ship your compiled binaries with turned on program database debug support. The main differences between ReleaseDebug and Release configurations is only ten bytes at the and of file, that contains path to PDB file. Benefits for such build are ability to debug release configuration under debugger and possibility to fix program crash without recompilation (I�d recommend to store PDB files for each builds as well as sources).

Here are steps to make ReleaseDebug configuration from Release one:

Revision:1, Last Modified: 05/14/01 22:32, by Vadim Melnik. Visit my Homepage.