mirror of
https://github.com/microsoft/mimalloc.git
synced 2025-05-21 06:19:31 +03:00
Move filling with MI_DEBUG_UNINIT out of _mi_page_malloc() into allocation functions
This mirrors how zero filling is handled.
This commit is contained in:
parent
1621b461c6
commit
9ef4e87743
3 changed files with 24 additions and 3 deletions
|
@ -148,6 +148,10 @@ void _mi_block_zero_init(const mi_page_t* page, void* p, size_t size);
|
|||
bool _mi_page_is_valid(mi_page_t* page);
|
||||
#endif
|
||||
|
||||
#if MI_DEBUG >= 2
|
||||
void _mi_debug_uninit_fill(void* p, size_t size);
|
||||
#endif
|
||||
|
||||
|
||||
// ------------------------------------------------------
|
||||
// Branches
|
||||
|
|
|
@ -83,6 +83,11 @@ static void* mi_heap_malloc_init_aligned_at(mi_heap_t* const heap, const size_t
|
|||
mi_assert_internal(p != NULL);
|
||||
mi_assert_internal(((uintptr_t)p + offset) % alignment == 0);
|
||||
if (init == MI_ALLOC_ZERO_INIT) { _mi_block_zero_init(page, p, size); }
|
||||
else if (init == MI_ALLOC_UNINIT) {
|
||||
#if MI_DEBUG >= 2
|
||||
_mi_debug_uninit_fill(p, size);
|
||||
#endif
|
||||
}
|
||||
return p;
|
||||
}
|
||||
}
|
||||
|
|
18
src/alloc.c
18
src/alloc.c
|
@ -37,9 +37,7 @@ extern inline void* _mi_page_malloc(mi_heap_t* heap, mi_page_t* page, size_t siz
|
|||
page->free = mi_block_next(page, block);
|
||||
mi_assert_internal(page->free == NULL || _mi_ptr_page(page->free) == page);
|
||||
|
||||
#if (MI_DEBUG>0)
|
||||
if (!page->is_zero) { memset(block, MI_DEBUG_UNINIT, size); }
|
||||
#elif (MI_SECURE!=0)
|
||||
#if (MI_SECURE!=0)
|
||||
block->next = 0; // don't leak internal data
|
||||
#endif
|
||||
|
||||
|
@ -90,6 +88,10 @@ static inline mi_decl_restrict void* _mi_heap_malloc_small_init(mi_heap_t* heap,
|
|||
#endif
|
||||
if (init == MI_ALLOC_ZERO_INIT && p != NULL) {
|
||||
_mi_block_zero_init(_mi_ptr_page(p),p,size); // todo: can we avoid getting the page again?
|
||||
} else if (init == MI_ALLOC_UNINIT && p != NULL) {
|
||||
#if MI_DEBUG >= 2
|
||||
_mi_debug_uninit_fill(p, size);
|
||||
#endif
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
@ -120,6 +122,10 @@ extern inline mi_decl_restrict void* _mi_heap_malloc_init(mi_heap_t* heap, size_
|
|||
#endif
|
||||
if (init == MI_ALLOC_ZERO_INIT && p != NULL) {
|
||||
_mi_block_zero_init(_mi_ptr_page(p),p,size); // todo: can we avoid getting the page again?
|
||||
} else if (init == MI_ALLOC_UNINIT && p != NULL) {
|
||||
#if MI_DEBUG >= 2
|
||||
_mi_debug_uninit_fill(p, size);
|
||||
#endif
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
@ -152,6 +158,12 @@ void _mi_block_zero_init(const mi_page_t* page, void* p, size_t size) {
|
|||
}
|
||||
}
|
||||
|
||||
#if MI_DEBUG >= 2
|
||||
void _mi_debug_uninit_fill(void* p, size_t size) {
|
||||
memset(p, MI_DEBUG_UNINIT, size);
|
||||
}
|
||||
#endif
|
||||
|
||||
// zero initialized small block
|
||||
mi_decl_restrict void* mi_zalloc_small(size_t size) mi_attr_noexcept {
|
||||
return _mi_heap_malloc_small_init(mi_get_default_heap(), size, MI_ALLOC_ZERO_INIT);
|
||||
|
|
Loading…
Add table
Reference in a new issue