Shakje

I'm looking for a problem with some particular code that's written in C and have been looking around the line that calls the "user break point" all of today just about. The HeapAlloc function is working fine and I've inspected the memory around pObjects (especially near the end) to make sure it's not an overrun and that everything is alloced cleanly.

nRecordMax is at 2000 here, but it fails even if I just insert a 1003 in its place (the heap is allocated to 1000 to begin with). All other code seems to be fine. Any ideas

Code Snippet

pTempObjectReAlloc = HeapReAlloc (GetProcessHeap(), HEAP_ZERO_MEMORY,
g_sGlobalStruct.pCurrentDS->pObjects,
(g_sGlobalStruct.pCurrentDS->nRecordMax * sizeof(DS_OBJECT_STRUCT)));




Re: Visual C++ Language HeapReAlloc user break point

Ramkrishna Pawar

Is the previous memory by any chance "non grawable" I see a note in MSDN, is this a condition with your project

dwBytes
[in] New size of the memory block, in bytes. A memory block's size can be increased or decreased by using this function.

If the heap specified by the hHeap parameter is a "non-growable" heap, dwBytes must be less than 0x7FFF8. You create a non-growable heap by calling the HeapCreate function with a nonzero value.






Re: Visual C++ Language HeapReAlloc user break point

Shakje

It uses GetProcessHeap() so there's no HeapCreate.




Re: Visual C++ Language HeapReAlloc user break point

Ramkrishna Pawar

Are you sure the applications default heap can be re-allocated




Re: Visual C++ Language HeapReAlloc user break point

Shakje

It's mentioned in the MSDN entry for HeapReAlloc as a possible entry for the first parameter, so unless there's some compiler switch I'm missing I don't see why not :/

I might just step through again to see if it's garbling the memory, it's just...stepping...through...1000...entries when the memory looks fine to me.

And I can't run it through Purify because it's a dll and the program loads in a ton of other dlls which Purify tries to instrument, and ends up failing on one which means I can't get into the place that this crashes.






Re: Visual C++ Language HeapReAlloc user break point

Shakje

Turns out there was a slight buffer overflow, which I only noticed after throwing it through windbg. Sorry to waste your time, but thanks for it.