ntdll: Use block helpers to iterate blocks in heap_validate.

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-04 20:38:18 +02:00 committed by Alexandre Julliard
parent 06681774af
commit 3001a2ff31
1 changed files with 7 additions and 10 deletions

View File

@ -286,7 +286,7 @@ static inline BOOL check_subheap( const SUBHEAP *subheap )
return contains( base, subheap->size, base + subheap->headerSize, subheap->commitSize - subheap->headerSize ); return contains( base, subheap->size, base + subheap->headerSize, subheap->commitSize - subheap->headerSize );
} }
static BOOL heap_validate( HEAP *heap ); static BOOL heap_validate( const HEAP *heap );
/* mark a block of memory as free for debugging purposes */ /* mark a block of memory as free for debugging purposes */
static inline void mark_block_free( void *ptr, SIZE_T size, DWORD flags ) static inline void mark_block_free( void *ptr, SIZE_T size, DWORD flags )
@ -1287,15 +1287,14 @@ static BOOL heap_validate_ptr( const HEAP *heap, const void *ptr, SUBHEAP **subh
return validate_used_block( *subheap, arena ); return validate_used_block( *subheap, arena );
} }
static BOOL heap_validate( HEAP *heap ) static BOOL heap_validate( const HEAP *heap )
{ {
const ARENA_LARGE *large_arena; const ARENA_LARGE *large_arena;
const struct block *block;
const SUBHEAP *subheap; const SUBHEAP *subheap;
LIST_FOR_EACH_ENTRY( subheap, &heap->subheap_list, SUBHEAP, entry ) LIST_FOR_EACH_ENTRY( subheap, &heap->subheap_list, SUBHEAP, entry )
{ {
char *ptr = (char *)subheap->base + subheap->headerSize;
if (!check_subheap( subheap )) if (!check_subheap( subheap ))
{ {
ERR( "heap %p, subheap %p corrupted sizes\n", heap, subheap ); ERR( "heap %p, subheap %p corrupted sizes\n", heap, subheap );
@ -1303,17 +1302,15 @@ static BOOL heap_validate( HEAP *heap )
return FALSE; return FALSE;
} }
while (ptr < (char *)subheap->base + subheap->size) for (block = first_block( subheap ); block; block = next_block( subheap, block ))
{ {
if (*(DWORD *)ptr & ARENA_FLAG_FREE) if (block_get_flags( block ) & ARENA_FLAG_FREE)
{ {
if (!validate_free_block( subheap, (ARENA_INUSE *)ptr )) return FALSE; if (!validate_free_block( subheap, block )) return FALSE;
ptr += sizeof(ARENA_FREE) + (*(DWORD *)ptr & ARENA_SIZE_MASK);
} }
else else
{ {
if (!validate_used_block( subheap, (ARENA_INUSE *)ptr )) return FALSE; if (!validate_used_block( subheap, block )) return FALSE;
ptr += sizeof(ARENA_INUSE) + (*(DWORD *)ptr & ARENA_SIZE_MASK);
} }
} }
} }