Somewhat reorganize functions to ensure control over block initialization (or lack thereof)

If all "public" functions internally call a helper with the desired "initialization"
mode (zero or unitialized) we can ensure that a block is only filled once.

Otherwise, if a "public" function would call another "public" function, it could happen
that a block is first filled with the "uninit memory" marker in debug mode, after which
it's immediately overwritten with all zeroes.
This commit is contained in:
Frank Richter 2021-12-19 21:03:38 +01:00
parent 7cd7224e3e
commit 1621b461c6
3 changed files with 42 additions and 40 deletions

View file

@ -138,8 +138,8 @@ mi_msecs_t _mi_clock_start(void);
// "alloc.c"
void* _mi_page_malloc(mi_heap_t* heap, mi_page_t* page, size_t size) mi_attr_noexcept; // called from `_mi_malloc_generic`
void* _mi_heap_malloc_zero(mi_heap_t* heap, size_t size, mi_alloc_init_t init);
void* _mi_heap_realloc_zero(mi_heap_t* heap, void* p, size_t newsize, mi_alloc_init_t init);
void* _mi_heap_malloc_init(mi_heap_t* heap, size_t size, mi_alloc_init_t init) mi_attr_noexcept;
void* _mi_heap_realloc_init(mi_heap_t* heap, void* p, size_t newsize, mi_alloc_init_t init);
mi_block_t* _mi_page_ptr_unalign(const mi_segment_t* segment, const mi_page_t* page, const void* p);
bool _mi_free_delayed_block(mi_block_t* block);
void _mi_block_zero_init(const mi_page_t* page, void* p, size_t size);