When we declare variables without initializing them, windows memory management functions initialize memory with some special values, depending on their type (static or dynamic). The compiler assigns some default values to different types of variables. These values become very useful during debugging because we can find why some exceptions has occurred. Some common values and their meanings are discussed below:
Windows NT memory codes
* 0xfeeefeee - Memory reserved to heap allocation but has not been allocated yet [ 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(). ]
* 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.
Compiler initializations
* 0xcccccccc - Uninitialized stack variable [ 0xCC, 0xCCCCCCCC - The /GX Microsoft Visual C++ compiler option initializes all local variables which are not explicitly initialized by the program. All memory used by these variables are thus filled with 0xCC, 0xCCCCCCCC. ]
Debug codes provided by C runtime library
* 0xcdcdcdcd - Uninitialized heap variables( i.e. New objects) [ New objects are filled with 0xCD when they are allocated.]
* 0xfdfdfdfd - Padding around an array(called 'No-man's land memory'. They are Extra bytes that belong to the internal block allocated, but not the block you requested. They are placed before and after requested blocks and are used for data bound checking.)
* 0xdddddddd - Released heap variable (delete or free)[ 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. In some cases it will be overwritten by some other debug functions
When a debugger is attached to a process, HeapAlloc will initialize memory to 0xbaadf00d and HeapFree will set deleted memory to 0xfeeefeee.
No comments:
Post a Comment