Visual Studio - how to find source of heap corruption errors

Danne picture Danne · Mar 18, 2010 · Viewed 61.1k times · Source

I wonder if there is a good way to find the source code that causes a heap corruption error, given the memory address of the data that was written 'outside' the allocated heap block in Visual Studio;

Dedicated (0008) free list element 26F7F670 is wrong size (dead)

(Trying to write down some notes on how to find memory errors)

Answer

Andreas Brinck picture Andreas Brinck · Mar 19, 2010

Begin with installing windbg:

http://www.microsoft.com/whdc/Devtools/Debugging/default.mspx

Then turn on the pageheap like this:

gflags.exe –p /enable yourexecutable.exe /full

This will insert a non writable page after each heap allocation.

After this launch the executable from inside windbg, any writes outside the heap will now be caught by this debugger. To turn of the pageheap afterwards use this:

gflags.exe -p /disable yourexecutable.exe

More info on how to use the pageheap here.