From 20ca02e4c176f58029c893ec23c2c9b2d799beb2 Mon Sep 17 00:00:00 2001 From: Austen Stone Date: Wed, 26 Nov 2025 17:18:59 -0500 Subject: [PATCH] Fix crash in pthread_tsd_cleanup on macOS ARM64 (#1177) Complete the NULL handling fix from commit 515047b by also checking for NULL page entries in the 2-level page map lookup. The issue occurs on macOS ARM64 during pthread TSD cleanup when thread_local C++ objects are destroyed. During this late cleanup phase, the TLS for mimalloc may already be invalidated, causing page map lookups to return NULL for valid pointers. Commit 515047b changed the sub==NULL case to return _mi_page_empty instead of NULL, but missed the case where sub[sub_idx] is NULL. --- include/mimalloc/internal.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/include/mimalloc/internal.h b/include/mimalloc/internal.h index 4a456ad9..1e53e0da 100644 --- a/include/mimalloc/internal.h +++ b/include/mimalloc/internal.h @@ -578,7 +578,9 @@ static inline mi_page_t* _mi_checked_ptr_page(const void* p) { const size_t idx = _mi_page_map_index(p, &sub_idx); mi_submap_t const sub = _mi_page_map[idx]; if mi_unlikely(sub == NULL) return (mi_page_t*)&_mi_page_empty; - return sub[sub_idx]; + mi_page_t* const page = sub[sub_idx]; + if mi_unlikely(page == NULL) return (mi_page_t*)&_mi_page_empty; + return page; } #endif