Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/ntdll/heap.c | 42 +++++++++++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 11 deletions(-)
diff --git a/dlls/ntdll/heap.c b/dlls/ntdll/heap.c index 31a7ba18d61..b7dab61dcd9 100644 --- a/dlls/ntdll/heap.c +++ b/dlls/ntdll/heap.c @@ -1004,20 +1004,13 @@ static SUBHEAP *HEAP_CreateSubHeap( HEAP *heap, LPVOID address, DWORD flags,
/*********************************************************************** - * HEAP_FindFreeBlock - * - * Find a free block at least as large as the requested size, and make sure - * the requested size is committed. + * find_free_block_in_list */ -static ARENA_FREE *HEAP_FindFreeBlock( HEAP *heap, SIZE_T size, - SUBHEAP **ppSubHeap ) +static ARENA_FREE *find_free_block_in_list( HEAP *heap, SIZE_T size, FREE_LIST_ENTRY *pEntry, + SUBHEAP **ppSubHeap ) { SUBHEAP *subheap; struct list *ptr; - SIZE_T total_size; - FREE_LIST_ENTRY *pEntry = heap->freeList + get_freelist_index( size + sizeof(ARENA_INUSE) ); - - /* Find a suitable free list, and in it find a block large enough */
ptr = &pEntry->arena.entry; while ((ptr = list_next( &heap->freeList[0].arena.entry, ptr ))) @@ -1028,12 +1021,39 @@ static ARENA_FREE *HEAP_FindFreeBlock( HEAP *heap, SIZE_T size, if (arena_size >= size) { subheap = HEAP_FindSubHeap( heap, pArena ); - if (!HEAP_Commit( subheap, (ARENA_INUSE *)pArena, size )) return NULL; *ppSubHeap = subheap; return pArena; } }
+ return NULL; +} + + +/*********************************************************************** + * HEAP_FindFreeBlock + * + * Find a free block at least as large as the requested size, and make sure + * the requested size is committed. + */ +static ARENA_FREE *HEAP_FindFreeBlock( HEAP *heap, SIZE_T size, + SUBHEAP **ppSubHeap ) +{ + SUBHEAP *subheap; + SIZE_T total_size, index = get_freelist_index( size + sizeof(ARENA_INUSE) ); + FREE_LIST_ENTRY *pEntry = NULL; + ARENA_FREE *pArena; + + /* Find a suitable free list, and in it find a block large enough */ + + if (index < HEAP_NB_FREE_LISTS) pEntry = heap->freeList + index; + + if (pEntry && (pArena = find_free_block_in_list( heap, size, pEntry, ppSubHeap ))) + { + if (!HEAP_Commit( *ppSubHeap, (ARENA_INUSE *)pArena, size )) return NULL; + return pArena; + } + /* If no block was found, attempt to grow the heap */
if (!(heap->flags & HEAP_GROWABLE))