ntdll: Update block unused_bytes in shrink_used_block.

Signed-off-by: Rémi Bernon <rbernon@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Rémi Bernon 2022-05-03 23:57:48 +02:00 committed by Alexandre Julliard
parent 481ecc2d72
commit 0c856978f1
1 changed files with 6 additions and 7 deletions

View File

@ -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); SIZE_T old_data_size = block_get_size( block ) - sizeof(*block);
if (old_data_size >= data_size + HEAP_MIN_SHRINK_SIZE) if (old_data_size >= data_size + HEAP_MIN_SHRINK_SIZE)
{ {
block->size = data_size | block_get_flags( block ); 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 ); HEAP_CreateFreeBlock( subheap, next_block( subheap, block ), old_data_size - data_size );
} }
else else
{ {
struct block *next; struct block *next;
block->unused_bytes = old_data_size - size;
if ((next = next_block( subheap, block ))) next->size &= ~ARENA_FLAG_PREV_FREE; 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 the block */
shrink_used_block( subheap, pInUse, rounded_size ); shrink_used_block( subheap, pInUse, rounded_size, size );
pInUse->unused_bytes = (pInUse->size & ARENA_SIZE_MASK) - size;
notify_alloc( pInUse + 1, size, flags & HEAP_ZERO_MEMORY ); notify_alloc( pInUse + 1, size, flags & HEAP_ZERO_MEMORY );
initialize_block( pInUse + 1, size, pInUse->unused_bytes, flags ); 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 ); pArena->size += block_get_size( next );
if (!HEAP_Commit( subheap, pArena, rounded_size )) return STATUS_NO_MEMORY; if (!HEAP_Commit( subheap, pArena, rounded_size )) return STATUS_NO_MEMORY;
notify_realloc( pArena + 1, oldActualSize, size ); notify_realloc( pArena + 1, oldActualSize, size );
shrink_used_block( subheap, pArena, rounded_size ); shrink_used_block( subheap, pArena, rounded_size, size );
} }
else else
{ {
@ -1703,11 +1704,9 @@ static NTSTATUS heap_reallocate( HEAP *heap, ULONG flags, void *ptr, SIZE_T size
else else
{ {
notify_realloc( pArena + 1, oldActualSize, size ); 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 */ /* Clear the extra bytes if needed */
if (size > oldActualSize) if (size > oldActualSize)