Rémi Bernon : ntdll: Use block helpers to iterate blocks in heap_validate.

Alexandre Julliard julliard at winehq.org
Tue May 17 15:37:22 CDT 2022


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

Author: Rémi Bernon <rbernon at codeweavers.com>
Date:   Wed May  4 20:38:18 2022 +0200

ntdll: Use block helpers to iterate blocks in heap_validate.

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, 7 insertions(+), 10 deletions(-)

diff --git a/dlls/ntdll/heap.c b/dlls/ntdll/heap.c
index 85964d04a59..b11218bc7a6 100644
--- a/dlls/ntdll/heap.c
+++ b/dlls/ntdll/heap.c
@@ -286,7 +286,7 @@ static inline BOOL check_subheap( const SUBHEAP *subheap )
     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 */
 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 );
 }
 
-static BOOL heap_validate( HEAP *heap )
+static BOOL heap_validate( const HEAP *heap )
 {
     const ARENA_LARGE *large_arena;
+    const struct block *block;
     const SUBHEAP *subheap;
 
     LIST_FOR_EACH_ENTRY( subheap, &heap->subheap_list, SUBHEAP, entry )
     {
-        char *ptr = (char *)subheap->base + subheap->headerSize;
-
         if (!check_subheap( subheap ))
         {
             ERR( "heap %p, subheap %p corrupted sizes\n", heap, subheap );
@@ -1303,17 +1302,15 @@ static BOOL heap_validate( HEAP *heap )
             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;
-                ptr += sizeof(ARENA_FREE) + (*(DWORD *)ptr & ARENA_SIZE_MASK);
+                if (!validate_free_block( subheap, block )) return FALSE;
             }
             else
             {
-                if (!validate_used_block( subheap, (ARENA_INUSE *)ptr )) return FALSE;
-                ptr += sizeof(ARENA_INUSE) + (*(DWORD *)ptr & ARENA_SIZE_MASK);
+                if (!validate_used_block( subheap, block )) return FALSE;
             }
         }
     }




More information about the wine-cvs mailing list