Rémi Bernon : ntdll: Update block unused_bytes in shrink_used_block.

Alexandre Julliard julliard at winehq.org
Wed May 18 15:38:31 CDT 2022


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

Author: Rémi Bernon <rbernon at codeweavers.com>
Date:   Tue May  3 23:57:48 2022 +0200

ntdll: Update block unused_bytes in shrink_used_block.

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

---

 dlls/ntdll/heap.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/dlls/ntdll/heap.c b/dlls/ntdll/heap.c
index f0f8704029c..44c9ad53196 100644
--- a/dlls/ntdll/heap.c
+++ b/dlls/ntdll/heap.c
@@ -808,17 +808,19 @@ static void HEAP_MakeInUseBlockFree( SUBHEAP *subheap, ARENA_INUSE *pArena )
 }
 
 
-static void shrink_used_block( SUBHEAP *subheap, struct block *block, SIZE_T data_size )
+static void shrink_used_block( SUBHEAP *subheap, struct block *block, SIZE_T data_size, SIZE_T size )
 {
     SIZE_T old_data_size = block_get_size( block ) - sizeof(*block);
     if (old_data_size >= data_size + HEAP_MIN_SHRINK_SIZE)
     {
         block->size = data_size | block_get_flags( block );
+        block->unused_bytes = data_size - size;
         HEAP_CreateFreeBlock( subheap, next_block( subheap, block ), old_data_size - data_size );
     }
     else
     {
         struct block *next;
+        block->unused_bytes = old_data_size - size;
         if ((next = next_block( subheap, block ))) next->size &= ~ARENA_FLAG_PREV_FREE;
     }
 }
@@ -1579,8 +1581,7 @@ static NTSTATUS heap_allocate( HEAP *heap, ULONG flags, SIZE_T size, void **ret
 
     /* Shrink the block */
 
-    shrink_used_block( subheap, pInUse, rounded_size );
-    pInUse->unused_bytes = (pInUse->size & ARENA_SIZE_MASK) - size;
+    shrink_used_block( subheap, pInUse, rounded_size, size );
 
     notify_alloc( pInUse + 1, size, flags & HEAP_ZERO_MEMORY );
     initialize_block( pInUse + 1, size, pInUse->unused_bytes, flags );
@@ -1687,7 +1688,7 @@ static NTSTATUS heap_reallocate( HEAP *heap, ULONG flags, void *ptr, SIZE_T size
             pArena->size += block_get_size( next );
             if (!HEAP_Commit( subheap, pArena, rounded_size )) return STATUS_NO_MEMORY;
             notify_realloc( pArena + 1, oldActualSize, size );
-            shrink_used_block( subheap, pArena, rounded_size );
+            shrink_used_block( subheap, pArena, rounded_size, size );
         }
         else
         {
@@ -1703,11 +1704,9 @@ static NTSTATUS heap_reallocate( HEAP *heap, ULONG flags, void *ptr, SIZE_T size
     else
     {
         notify_realloc( pArena + 1, oldActualSize, size );
-        shrink_used_block( subheap, pArena, rounded_size );
+        shrink_used_block( subheap, pArena, rounded_size, size );
     }
 
-    pArena->unused_bytes = (pArena->size & ARENA_SIZE_MASK) - size;
-
     /* Clear the extra bytes if needed */
 
     if (size > oldActualSize)




More information about the wine-cvs mailing list