I have HEAP big trouble

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



(Sorry if this is not the right newsgroup - couldn't find a more appropriate
one).
I'm trying to find a problem in my program and I suspected a problem with
the heap - maybe leaky code. So I was looking at the heap usage with a small
function I found on the internet somehwere. Only trouble is that it entered
an infinite loop. I think this might point to a problem but I don't know what
it is. Here's the code with an additional fix to catch the inifinite loop:

int CountWalk()
{
int HeapStatus;
int lastPentry = 0;
BOOL running = TRUE;
_HEAPINFO info;
info._pentry = NULL;
int UsedBytes = 0;

while(running)
{ /* scan heap */
HeapStatus = _heapwalk(&info);
switch(HeapStatus)
{ /* check status */
case _HEAPOK:
break;
case _HEAPEND:
running = FALSE;
break;
default:
ASSERT(FALSE);
running = FALSE;
continue;
} /* check status */

if(info._useflag == _USEDENTRY)
{ /* used block */
UsedBytes += info._size;
} /* used block */

// extra termination required to avoid infinite loop !!!
if ((int)info._pentry == lastPentry)
running = FALSE;
else
lastPentry = (int)info._pentry;
} /* scan heap */
return UsedBytes;
} // CMemStatsDlg::CountWalk

What was happening was that _heapwalk() was returning the same unused heap
block. I know this because the _pentry data didn't change. The status return
was _HEAPOK.

Anyone got any idea what sort of error could put the heap into a state where
_heapwalk() could malfunction this way?

Alan
(VS6 C++)

.



Relevant Pages

  • Re: I have HEAP big trouble
    ... So I was looking at the heap usage with a small ... int CountWalk() ... // extra termination required to avoid infinite loop!!! ...
    (microsoft.public.vc.debugger)
  • would yo please provide help?
    ... i have written a code of a 'MINIMUM' Heap the code seems ... private int maxSize; ... int largerChild; ... String sel; ...
    (comp.lang.java.programmer)
  • Re: smail remote and local root holes (really, it is exploitable)
    ... * heap is at 0x080d.. ... ssize_t Send(int s, const void *buf, size_t len, int flags) ...
    (Bugtraq)
  • Heap fragmentation
    ... in University I learnt about heap fragmentation, ... over this procedure I cycle a hundred times. ... int main{ ...
    (comp.realtime)
  • Re: comm assembler directive
    ... You'll find explicit code for clearing the .bss area. ... "heap" is a `c` term and I'm not too concerned ... A .bss .stack collision seems to be the preferred failure ... int a; ...
    (comp.lang.asm.x86)