Jinoh Kang (@iamahuman) commented about dlls/ntdll/heap.c:
old_block_size = block_get_size( block ); *old_size = old_block_size - block_get_overhead( block );
old_bin = BLOCK_SIZE_BIN( old_block_size );
if (block_size >= HEAP_MIN_LARGE_BLOCK_SIZE) return STATUS_NO_MEMORY; /* growing small block to large block */
if (block_get_flags( block ) & BLOCK_FLAG_LFH)
{
/* as native LFH does it with different block size: refuse to resize even though we could */
if (ROUND_SIZE( *old_size, BLOCK_ALIGN - 1) != ROUND_SIZE( size, BLOCK_ALIGN - 1)) return STATUS_NO_MEMORY;
if (size >= *old_size) return STATUS_NO_MEMORY;
block_set_flags( block, BLOCK_FLAG_USER_MASK & ~BLOCK_FLAG_USER_INFO, BLOCK_USER_FLAGS( flags ) );
block->tail_size = old_block_size - sizeof(*block) - size;
initialize_block( block, *old_size, size, flags );
mark_block_tail( block, flags );
`heap_resize_block` is already too complex. How about factoring this out into a following helper function?
```c /* Finish resizing a block of memory and re-initialize it. */ static void commit_block_resize( struct block *block, SIZE_T old_size, SIZE_T size, DWORD flags ) { valgrind_notify_resize( block + 1, old_size, size ); block_set_flags( block, BLOCK_FLAG_USER_MASK & ~BLOCK_FLAG_USER_INFO, BLOCK_USER_FLAGS( flags ) ); block->tail_size = block_get_size( block ) - sizeof(*block) - size; initialize_block( block, old_size, size, flags ); mark_block_tail( block, flags ); } ```
Feel free to rename it if the "commit" part feels like it will be easily confused with virtual memory commitment.