Debugging HeapReAlloc() failure using GetExceptionCode()
I have a HeapReAlloc()
failing with the error A开发者_高级运维CCESS_VIOLATION
, but I'm unsure how to implement a further check using GetExceptionCode()
as it uses try/catch or exception or something - can someone give me an example of how I can use it to narrow down this failure?
You are trouble-shooting the wrong problem. HeapRealloc() is bombing because the heap is corrupted. That happened a while ago, some statement in your program overflowing a heap block, writing data to memory that was freed, something like that. MSVC has a debug memory allocator to help you troubleshoot these kind of problems, look in the MSDN library for <crtdbg.h>
.
Make sure hHeap
and lpMem
parameters of HeapReAlloc
are valid.
You should take the following possible root of causes into account.
- What value is passes for
dwFlags
. - How
hHeap
is obtained.- via
HeapCreate
- or
GetProcessHeap
- via
- What parameters are provided to
HeapCreate
/GetProcessHeap
.
In addition to HeapValidate(hHeap, 0, lpMem)
, you should also validate the entire heap by calling
HeapValidate(hHeap, 0, NULL)
精彩评论