Search code examples
cwindows-xpheap-corruption

how to debug possible heap corruption?


VS2008, C. Also using some pre-built libraries. When I step through my code in the debugger and over the library functions being called, I get this:

HEAP[unit_test.exe]: Heap missing last entry in committed range near 35c70 Windows has triggered a breakpoint in unit_test.exe.

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

This may also be due to the user pressing F12 while unit_test.exe has focus.

The output window may have more diagnostic information.

Any ideas on how to debug this?

Update: I refactored the code and see that I get the popup when doing a printf(). I also get it when there is a free(). I commented out those lines and now when there is a malloc(), I get the heap corruption popup dialog.


Solution

  • I'd suggest you start by using Application Verifier to test for heap corruption. Application Verifier is a free tool from Microsoft that helps identify resource leaks and heap corruption. You can find App Verifier at url: http://www.microsoft.com/en-us/download/details.aspx?displaylang=en&id=20028 You can find out how to enable it for heap corruption and other things from http://technet.microsoft.com/en-us/library/bb457063.aspx

    It is often useful in these situations.