{
HEAP *heapPtr = HEAP_GetPtr( heap );
SUBHEAP *subheap;
- ULONG i;
+ ULONG i, flags;
TRACE("%08x\n", heap );
if (!heapPtr) return FALSE;
RtlDeleteCriticalSection( &heapPtr->critSection );
subheap = &heapPtr->subheap;
+ // We must save the flags. The first subheap is located after
+ // the heap structure. If we release the first subheap,
+ // we release also the heap structure.
+ flags = heapPtr->flags;
while (subheap)
{
SUBHEAP *next = subheap->next;
- if (!(heapPtr->flags & HEAP_NO_VALLOC))
+ if (!(flags & HEAP_NO_VALLOC))
{
ULONG dummySize = 0;
ZwFreeVirtualMemory(NtCurrentProcess(),