@@ -26,6 +26,15 @@ terms of the MIT license. A copy of the license can be found in the file
26
26
// Allocation
27
27
// ------------------------------------------------------
28
28
29
+ #if (MI_DEBUG > 0 )
30
+ static void mi_debug_fill (mi_page_t * page , mi_block_t * block , int c , size_t size ) {
31
+ size_t offset = (size_t )page -> debug_offset ;
32
+ if (offset < size ) {
33
+ memset ((char * )block + offset , c , size - offset );
34
+ }
35
+ }
36
+ #endif
37
+
29
38
// Fast allocation in a page: just pop from the free list.
30
39
// Fall back to generic allocation only if the list is empty.
31
40
extern inline void * _mi_page_malloc (mi_heap_t * heap , mi_page_t * page , size_t size , bool zero ) mi_attr_noexcept {
@@ -65,7 +74,7 @@ extern inline void* _mi_page_malloc(mi_heap_t* heap, mi_page_t* page, size_t siz
65
74
66
75
#if (MI_DEBUG > 0 ) && !MI_TRACK_ENABLED && !MI_TSAN
67
76
if (!zero && !mi_page_is_huge (page )) {
68
- memset ( block , MI_DEBUG_UNINIT , mi_page_usable_block_size (page ));
77
+ mi_debug_fill ( page , block , MI_DEBUG_UNINIT , mi_page_usable_block_size (page ));
69
78
}
70
79
#elif (MI_SECURE != 0 )
71
80
if (!zero ) { block -> next = 0 ; } // don't leak internal data
@@ -426,7 +435,7 @@ static mi_decl_noinline void _mi_free_block_mt(mi_page_t* page, mi_block_t* bloc
426
435
427
436
#if (MI_DEBUG > 0 ) && !MI_TRACK_ENABLED && !MI_TSAN // note: when tracking, cannot use mi_usable_size with multi-threading
428
437
if (segment -> kind != MI_SEGMENT_HUGE ) { // not for huge segments as we just reset the content
429
- memset ( block , MI_DEBUG_FREED , mi_usable_size (block ));
438
+ mi_debug_fill ( page , block , MI_DEBUG_FREED , mi_usable_size (block ));
430
439
}
431
440
#endif
432
441
@@ -480,7 +489,7 @@ static inline void _mi_free_block(mi_page_t* page, bool local, mi_block_t* block
480
489
mi_check_padding (page , block );
481
490
#if (MI_DEBUG > 0 ) && !MI_TRACK_ENABLED && !MI_TSAN
482
491
if (!mi_page_is_huge (page )) { // huge page content may be already decommitted
483
- memset ( block , MI_DEBUG_FREED , mi_page_block_size (page ));
492
+ mi_debug_fill ( page , block , MI_DEBUG_FREED , mi_page_block_size (page ));
484
493
}
485
494
#endif
486
495
mi_block_set_next (page , block , page -> local_free );
@@ -575,7 +584,7 @@ void mi_free(void* p) mi_attr_noexcept
575
584
mi_check_padding (page , block );
576
585
mi_stat_free (page , block );
577
586
#if (MI_DEBUG > 0 ) && !MI_TRACK_ENABLED && !MI_TSAN
578
- memset ( block , MI_DEBUG_FREED , mi_page_block_size (page ));
587
+ mi_debug_fill ( page , block , MI_DEBUG_FREED , mi_page_block_size (page ));
579
588
#endif
580
589
mi_track_free_size (p , mi_page_usable_size_of (page ,block )); // faster then mi_usable_size as we already know the page and that p is unaligned
581
590
mi_block_set_next (page , block , page -> local_free );
0 commit comments