Alexandre Julliard : ntdll: Fill existing tail and free blocks when the debug flags are changed after heap creation .
Alexandre Julliard
julliard at winehq.org
Tue Jan 26 11:21:09 CST 2010
Module: wine
Branch: master
Commit: a19269509910b95ae20247608010638a4832bd75
URL: http://source.winehq.org/git/wine.git/?a=commit;h=a19269509910b95ae20247608010638a4832bd75
Author: Alexandre Julliard <julliard at winehq.org>
Date: Tue Jan 26 14:31:22 2010 +0100
ntdll: Fill existing tail and free blocks when the debug flags are changed after heap creation.
---
dlls/ntdll/heap.c | 34 ++++++++++++++++++++++++++++++++--
1 files changed, 32 insertions(+), 2 deletions(-)
diff --git a/dlls/ntdll/heap.c b/dlls/ntdll/heap.c
index d8291b8..9d020ee 100644
--- a/dlls/ntdll/heap.c
+++ b/dlls/ntdll/heap.c
@@ -1273,6 +1273,7 @@ void heap_set_debug_flags( HANDLE handle )
ULONG flags = 0;
if (TRACE_ON(heap)) global_flags |= FLG_HEAP_VALIDATE_ALL;
+ if (WARN_ON(heap)) global_flags |= FLG_HEAP_VALIDATE_PARAMETERS;
if (global_flags & FLG_HEAP_ENABLE_TAIL_CHECK) flags |= HEAP_TAIL_CHECKING_ENABLED;
if (global_flags & FLG_HEAP_ENABLE_FREE_CHECK) flags |= HEAP_FREE_CHECKING_ENABLED;
@@ -1286,10 +1287,39 @@ void heap_set_debug_flags( HANDLE handle )
flags |= HEAP_VALIDATE | HEAP_VALIDATE_ALL |
HEAP_TAIL_CHECKING_ENABLED | HEAP_FREE_CHECKING_ENABLED;
- if (WARN_ON(heap)) flags |= HEAP_VALIDATE | HEAP_VALIDATE_PARAMS | HEAP_FREE_CHECKING_ENABLED;
-
heap->flags |= flags;
heap->force_flags |= flags & ~(HEAP_VALIDATE | HEAP_DISABLE_COALESCE_ON_FREE);
+
+ if (flags & (HEAP_FREE_CHECKING_ENABLED | HEAP_TAIL_CHECKING_ENABLED)) /* fix existing blocks */
+ {
+ SUBHEAP *subheap;
+
+ LIST_FOR_EACH_ENTRY( subheap, &heap->subheap_list, SUBHEAP, entry )
+ {
+ char *ptr = (char *)subheap->base + subheap->headerSize;
+ char *end = (char *)subheap->base + subheap->commitSize;
+ while (ptr < end)
+ {
+ ARENA_INUSE *arena = (ARENA_INUSE *)ptr;
+ SIZE_T size = arena->size & ARENA_SIZE_MASK;
+ if (arena->size & ARENA_FLAG_FREE)
+ {
+ SIZE_T count = size;
+
+ ptr += sizeof(ARENA_FREE) + size;
+ if (ptr > end) count = end - (char *)((ARENA_FREE *)arena + 1);
+ else count -= sizeof(DWORD);
+ mark_block_free( (ARENA_FREE *)arena + 1, count, flags );
+ }
+ else
+ {
+ mark_block_tail( (char *)(arena + 1) + size - arena->unused_bytes,
+ arena->unused_bytes, flags );
+ ptr += sizeof(ARENA_INUSE) + size;
+ }
+ }
+ }
+ }
}
More information about the wine-cvs
mailing list