views:

64

answers:

2

Hey folks,

Been messing about with this all day and haven't got anywhere so I'm hoping someone can help me - I have a HeapReAlloc method failing with the error ACCESS_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 a quick example of how I can use it to narrow down this failure, please?

Thanks very much, Becky

A: 

Are HeapReAlloc's hHeap and lpMem valid? What value are you passing for dwFlags? Did you obtain hHeap via HeapCreate or GetProcessHeap? What parameters have you provided to HeapCreate/GetProcessHeap?

vladr
hHeap is valid, passing HEAP_GENERATE_EXCEPTIONS | HEAP_ZERO_MEMORY for dwFlags, and lpMem is valid when I use HeapValidate just before the HeapReAlloc function call.
Becky Franklin
I use HeapCreate with the parameters HEAP_GENERATE_EXCEPTIONS,100000,0
Becky Franklin
@Becky, in addition to `HeapValidate(hHeap, 0, lpMem)` can you *also* call `HeapValidate(hHeap, 0, NULL)` to validate the entire heap?
vladr
+1  A: 

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>.

Hans Passant