Merge branch 'dev' into dev-exp

This commit is contained in:
daan 2019-11-07 10:34:06 -08:00
commit 36090dee5c
2 changed files with 8 additions and 6 deletions

View File

@ -26,7 +26,7 @@ terms of the MIT license. A copy of the license can be found in the file
// #define MI_SECURE 1 // guard page around metadata // #define MI_SECURE 1 // guard page around metadata
// #define MI_SECURE 2 // guard page around each mimalloc page // #define MI_SECURE 2 // guard page around each mimalloc page
// #define MI_SECURE 3 // encode free lists (detect corrupted free list (buffer overflow), and invalid pointer free) // #define MI_SECURE 3 // encode free lists (detect corrupted free list (buffer overflow), and invalid pointer free)
// #define MI_SECURE 4 // experimental, may be more expensive: checks for double free. // #define MI_SECURE 4 // experimental, may be more expensive: checks for double free. (cmake -DMI_SECURE_FULL=ON)
#if !defined(MI_SECURE) #if !defined(MI_SECURE)
#define MI_SECURE 4 #define MI_SECURE 4
@ -35,7 +35,7 @@ terms of the MIT license. A copy of the license can be found in the file
// Define MI_DEBUG for debug mode // Define MI_DEBUG for debug mode
// #define MI_DEBUG 1 // basic assertion checks and statistics, check double free, corrupted free list, and invalid pointer free. // #define MI_DEBUG 1 // basic assertion checks and statistics, check double free, corrupted free list, and invalid pointer free.
// #define MI_DEBUG 2 // + internal assertion checks // #define MI_DEBUG 2 // + internal assertion checks
// #define MI_DEBUG 3 // + extensive internal invariant checking // #define MI_DEBUG 3 // + extensive internal invariant checking (cmake -DMI_CHECK_FULL=ON)
#if !defined(MI_DEBUG) #if !defined(MI_DEBUG)
#if !defined(NDEBUG) || defined(_DEBUG) #if !defined(NDEBUG) || defined(_DEBUG)
#define MI_DEBUG 2 #define MI_DEBUG 2

View File

@ -455,8 +455,8 @@ static void mi_page_free_list_extend_secure(mi_heap_t* heap, mi_page_t* page, si
while ((extend >> shift) == 0) { while ((extend >> shift) == 0) {
shift--; shift--;
} }
size_t slice_count = (size_t)1U << shift; const size_t slice_count = (size_t)1U << shift;
size_t slice_extend = extend / slice_count; const size_t slice_extend = extend / slice_count;
mi_assert_internal(slice_extend >= 1); mi_assert_internal(slice_extend >= 1);
mi_block_t* blocks[MI_MAX_SLICES]; // current start of the slice mi_block_t* blocks[MI_MAX_SLICES]; // current start of the slice
size_t counts[MI_MAX_SLICES]; // available objects in the slice size_t counts[MI_MAX_SLICES]; // available objects in the slice
@ -470,7 +470,7 @@ static void mi_page_free_list_extend_secure(mi_heap_t* heap, mi_page_t* page, si
// set up first element // set up first element
size_t current = _mi_heap_random(heap) % slice_count; size_t current = _mi_heap_random(heap) % slice_count;
counts[current]--; counts[current]--;
page->free = blocks[current]; mi_block_t* const free_start = blocks[current];
// and iterate through the rest // and iterate through the rest
uintptr_t rnd = heap->random; uintptr_t rnd = heap->random;
for (size_t i = 1; i < extend; i++) { for (size_t i = 1; i < extend; i++) {
@ -490,7 +490,9 @@ static void mi_page_free_list_extend_secure(mi_heap_t* heap, mi_page_t* page, si
mi_block_set_next(page, block, blocks[next]); // and set next; note: we may have `current == next` mi_block_set_next(page, block, blocks[next]); // and set next; note: we may have `current == next`
current = next; current = next;
} }
mi_block_set_next(page, blocks[current], NULL); // end of the list // prepend to the free list (usually NULL)
mi_block_set_next(page, blocks[current], page->free); // end of the list
page->free = free_start;
heap->random = _mi_random_shuffle(rnd); heap->random = _mi_random_shuffle(rnd);
} }