Rémi Bernon : ntdll: Remove entries from the free list in HEAP_FindFreeBlock.

Alexandre Julliard julliard at winehq.org
Fri May 20 15:26:48 CDT 2022


Module: wine
Branch: master
Commit: 47f7dfcc2c726885951ae72223f7956f2183a965
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=47f7dfcc2c726885951ae72223f7956f2183a965

Author: Rémi Bernon <rbernon at codeweavers.com>
Date:   Tue May  3 19:54:27 2022 +0200

ntdll: Remove entries from the free list in HEAP_FindFreeBlock.

Signed-off-by: Rémi Bernon <rbernon at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/ntdll/heap.c | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/dlls/ntdll/heap.c b/dlls/ntdll/heap.c
index 55eb6a328fd..472f8f11adc 100644
--- a/dlls/ntdll/heap.c
+++ b/dlls/ntdll/heap.c
@@ -1067,23 +1067,24 @@ static SUBHEAP *HEAP_CreateSubHeap( HEAP *heap, LPVOID address, DWORD flags,
 static ARENA_FREE *HEAP_FindFreeBlock( HEAP *heap, SIZE_T data_size, SUBHEAP **ppSubHeap )
 {
     struct entry *entry = find_free_list( heap, data_size + sizeof(ARENA_INUSE), FALSE );
+    SIZE_T total_size, arena_size;
+    ARENA_FREE *pArena;
     SUBHEAP *subheap;
     struct list *ptr;
-    SIZE_T total_size;
 
     /* Find a suitable free list, and in it find a block large enough */
 
     ptr = &entry->entry;
     while ((ptr = list_next( &heap->freeList[0].arena.entry, ptr )))
     {
-        ARENA_FREE *pArena = LIST_ENTRY( ptr, ARENA_FREE, entry );
-        SIZE_T arena_size = (pArena->size & ARENA_SIZE_MASK) +
-                            sizeof(ARENA_FREE) - sizeof(ARENA_INUSE);
+        pArena = LIST_ENTRY( ptr, ARENA_FREE, entry );
+        arena_size = (pArena->size & ARENA_SIZE_MASK) + sizeof(ARENA_FREE) - sizeof(ARENA_INUSE);
         if (arena_size >= data_size)
         {
             subheap = find_subheap( heap, (struct block *)pArena, FALSE );
             if (!HEAP_Commit( subheap, (ARENA_INUSE *)pArena, data_size )) return NULL;
             *ppSubHeap = subheap;
+            list_remove( &pArena->entry );
             return pArena;
         }
     }
@@ -1120,7 +1121,9 @@ static ARENA_FREE *HEAP_FindFreeBlock( HEAP *heap, SIZE_T data_size, SUBHEAP **p
           subheap, subheap->size, heap );
 
     *ppSubHeap = subheap;
-    return (ARENA_FREE *)((char *)subheap->base + subheap->headerSize);
+    pArena = (ARENA_FREE *)((char *)subheap->base + subheap->headerSize);
+    list_remove( &pArena->entry );
+    return pArena;
 }
 
 
@@ -1553,10 +1556,6 @@ static NTSTATUS heap_allocate( HEAP *heap, ULONG flags, SIZE_T size, void **ret
 
     if (!(entry = HEAP_FindFreeBlock( heap, data_size, &subheap ))) return STATUS_NO_MEMORY;
 
-    /* Remove the arena from the free list */
-
-    list_remove( &entry->entry );
-
     /* Build the in-use arena */
 
     block = (struct block *)entry;




More information about the wine-cvs mailing list