I’m running an iterative procedure in c++, and after the first iteration is completed as I expected, I get the following error beginning the second:
Heap block at 00000000212005D0 modified at 0000000021200674 past
requested size of 94 Windows has triggered a breakpoint in
myProject.exe.This may be due to a corruption of the heap, which indicates a bug in
myProject.exe or any of the DLLs it has loaded.This may also be due to the user pressing F12 while
myProject.exe has focus.The output window may have more diagnostic information.
While showing this error, visual-c++ opens dbgheap.c, highlighting the section given:
extern "C" _CRTIMP int __cdecl _CrtIsValidHeapPointer(
const void * pUserData
)
{
if (!pUserData)
return FALSE;
if (!_CrtIsValidPointer(pHdr(pUserData), sizeof(_CrtMemBlockHeader), FALSE))
return FALSE;
return HeapValidate( _crtheap, 0, pHdr(pUserData) );
}
What might be the reason for this error?
That section is the method that checks the heap validity, it’s not the source of your problem.
You’re most likely dealing with a memory corruption, which can be hard to debug. Your best bet is to run a memory analyzer tool (such as Purify) or, if the codebase is small, look through it yourself, removing pieces until you find the source.
Of course, any kind of undefined behavior can lead to this. Most common sources are:
virtualdestructorconst_cast,reinterpret_cast)I’d start with a full rebuild though… you never know!