diff --git a/CMakeLists.txt b/CMakeLists.txt index 9a33b6c8..c632e45e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -370,7 +370,7 @@ if(MI_BUILD_SHARED) set_target_properties(mimalloc PROPERTIES VERSION ${mi_version} SOVERSION ${mi_version_major} OUTPUT_NAME ${mi_basename} ) target_compile_definitions(mimalloc PRIVATE ${mi_defines} MI_SHARED_LIB MI_SHARED_LIB_EXPORT) target_compile_options(mimalloc PRIVATE ${mi_cflags}) - target_link_libraries(mimalloc PRIVATE ${mi_libraries} -fsanitize=address) + target_link_libraries(mimalloc PRIVATE ${mi_libraries}) target_include_directories(mimalloc PUBLIC $ $ diff --git a/include/mimalloc-track.h b/include/mimalloc-track.h index 35fb786a..3a2c2741 100644 --- a/include/mimalloc-track.h +++ b/include/mimalloc-track.h @@ -8,11 +8,16 @@ terms of the MIT license. A copy of the license can be found in the file #ifndef MIMALLOC_TRACK_H #define MIMALLOC_TRACK_H -// ------------------------------------------------------ -// Track memory ranges with macros for tools like Valgrind -// address sanitizer, or other memory checkers. -// ------------------------------------------------------ +/* ------------------------------------------------------------------------------------------------------ +Track memory ranges with macros for tools like Valgrind +address sanitizer, or other memory checkers. +The macros are set up such that the size passed to `mi_track_free_size` +matches the size of the allocation, or the newsize of a `mi_track_resize` (currently unused though). + +The `size` is either byte precise (and what the user requested) if `MI_PADDING` is enabled, +or otherwise it is the full block size which may be larger than the original request. +-------------------------------------------------------------------------------------------------------*/ #if MI_VALGRIND diff --git a/src/alloc-aligned.c b/src/alloc-aligned.c index 76b6fc3b..250af7a7 100644 --- a/src/alloc-aligned.c +++ b/src/alloc-aligned.c @@ -65,6 +65,7 @@ static mi_decl_noinline void* mi_heap_malloc_zero_aligned_at_fallback(mi_heap_t* mi_page_set_has_aligned(page, true); _mi_padding_shrink(page, (mi_block_t*)p, adjust + size); } + // todo: expand padding if overallocated and p==aligned_p ? mi_assert_internal(mi_page_usable_block_size(_mi_ptr_page(p)) >= adjust + size); mi_assert_internal(p == _mi_page_ptr_unalign(_mi_ptr_segment(aligned_p), _mi_ptr_page(aligned_p), aligned_p)); @@ -83,9 +84,6 @@ static mi_decl_noinline void* mi_heap_malloc_zero_aligned_at_fallback(mi_heap_t* mi_track_free(p); mi_track_malloc(aligned_p, size, zero); } - else { - mi_track_resize(aligned_p, oversize, size); - } #endif return aligned_p; } diff --git a/src/alloc.c b/src/alloc.c index 5fc7ec21..7f0f314a 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -497,7 +497,7 @@ mi_block_t* _mi_page_ptr_unalign(const mi_segment_t* segment, const mi_page_t* p void mi_decl_noinline _mi_free_generic(const mi_segment_t* segment, mi_page_t* page, bool is_local, void* p) mi_attr_noexcept { mi_block_t* const block = (mi_page_has_aligned(page) ? _mi_page_ptr_unalign(segment, page, p) : (mi_block_t*)p); - mi_stat_free(page, block); // stat_free may access the padding + mi_stat_free(page, block); // stat_free may access the padding mi_track_free(p); _mi_free_block(page, is_local, block); } @@ -564,7 +564,7 @@ void mi_free(void* p) mi_attr_noexcept #if (MI_DEBUG!=0) && !MI_TRACK_ENABLED memset(block, MI_DEBUG_FREED, mi_page_block_size(page)); #endif - mi_track_free(p); + mi_track_free_size(p, mi_page_usable_size_of(page,block)); // faster then mi_usable_size as we already now the page and that p is unaligned mi_block_set_next(page, block, page->local_free); page->local_free = block; if mi_unlikely(--page->used == 0) { // using this expression generates better code than: page->used--; if (mi_page_all_free(page))