Skip to content

Commit 20ca02e

Browse files
committed
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.
1 parent 7a2a411 commit 20ca02e

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

include/mimalloc/internal.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,9 @@ static inline mi_page_t* _mi_checked_ptr_page(const void* p) {
578578
const size_t idx = _mi_page_map_index(p, &sub_idx);
579579
mi_submap_t const sub = _mi_page_map[idx];
580580
if mi_unlikely(sub == NULL) return (mi_page_t*)&_mi_page_empty;
581-
return sub[sub_idx];
581+
mi_page_t* const page = sub[sub_idx];
582+
if mi_unlikely(page == NULL) return (mi_page_t*)&_mi_page_empty;
583+
return page;
582584
}
583585

584586
#endif

0 commit comments

Comments
 (0)