fix bug in freeing huge OS page allocation spanning multiple huge OS pages

This commit is contained in:
daan 2021-12-18 11:37:00 -08:00
parent 89090510bd
commit f16435447c
2 changed files with 4 additions and 3 deletions

View File

@ -1254,8 +1254,8 @@ void* _mi_os_alloc_huge_os_pages(size_t pages, int numa_node, mi_msecs_t max_mse
}
}
mi_assert_internal(page*MI_HUGE_OS_PAGE_SIZE <= size);
if (pages_reserved != NULL) *pages_reserved = page;
if (psize != NULL) *psize = page * MI_HUGE_OS_PAGE_SIZE;
if (pages_reserved != NULL) { *pages_reserved = page; }
if (psize != NULL) { *psize = page * MI_HUGE_OS_PAGE_SIZE; }
return (page == 0 ? NULL : start);
}
@ -1267,6 +1267,7 @@ void _mi_os_free_huge_pages(void* p, size_t size, mi_stats_t* stats) {
while (size >= MI_HUGE_OS_PAGE_SIZE) {
_mi_os_free(base, MI_HUGE_OS_PAGE_SIZE, stats);
size -= MI_HUGE_OS_PAGE_SIZE;
base += MI_HUGE_OS_PAGE_SIZE;
}
}

View File

@ -163,7 +163,7 @@ int main(void) {
for (size_t align = 1; align <= MI_ALIGNMENT_MAX && ok; align *= 2) {
void* ps[8];
for (int i = 0; i < 8 && ok; i++) {
ps[i] = mi_malloc_aligned(align/2 /*size*/, align);
ps[i] = mi_malloc_aligned(align*13 /*size*/, align);
if (ps[i] == NULL || (uintptr_t)(ps[i]) % align != 0) {
ok = false;
}