@@ -26,6 +26,15 @@ terms of the MIT license. A copy of the license can be found in the file
2626// Allocation
2727// ------------------------------------------------------
2828
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+
2938// Fast allocation in a page: just pop from the free list.
3039// Fall back to generic allocation only if the list is empty.
3140extern 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
6574
6675#if (MI_DEBUG > 0 ) && !MI_TRACK_ENABLED && !MI_TSAN
6776 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 ));
6978 }
7079#elif (MI_SECURE != 0 )
7180 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
426435
427436 #if (MI_DEBUG > 0 ) && !MI_TRACK_ENABLED && !MI_TSAN // note: when tracking, cannot use mi_usable_size with multi-threading
428437 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 ));
430439 }
431440 #endif
432441
@@ -480,7 +489,7 @@ static inline void _mi_free_block(mi_page_t* page, bool local, mi_block_t* block
480489 mi_check_padding (page , block );
481490 #if (MI_DEBUG > 0 ) && !MI_TRACK_ENABLED && !MI_TSAN
482491 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 ));
484493 }
485494 #endif
486495 mi_block_set_next (page , block , page -> local_free );
@@ -575,7 +584,7 @@ void mi_free(void* p) mi_attr_noexcept
575584 mi_check_padding (page , block );
576585 mi_stat_free (page , block );
577586 #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 ));
579588 #endif
580589 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
581590 mi_block_set_next (page , block , page -> local_free );
0 commit comments