Skip to content

Conversation

@austenstone
Copy link
Member

@austenstone austenstone commented Nov 26, 2025

Fixes #1177

On macOS ARM64, freeing memory during thread exit can crash when thread_local C++ objects are involved. The issue is that _mi_checked_ptr_page checks for sub == NULL but not for sub[sub_idx] == NULL - commit 515047b fixed the first case but missed the second.

This adds the missing NULL check so both cases return _mi_page_empty consistently.

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.
@austenstone austenstone changed the base branch from dev to dev3-cdb November 26, 2025 22:19
@austenstone
Copy link
Member Author

@microsoft-github-policy-service agree company="Microsoft"

@bazineta
Copy link

bazineta commented Nov 30, 2025

@austenstone I'm digging further, but this change trips the UB sanitizer on my ARM Mac when landed against the dev3 branch. I see you've landed it against the dev3-cdb branch, which I can't find documented anywhere, so that might be my problem.

@daanx
Copy link
Collaborator

daanx commented Dec 3, 2025

@austenstone I'm digging further, but this change trips the UB sanitizer on my ARM Mac when landed against the dev3 branch. I see you've landed it against the dev3-cdb branch, which I can't find documented anywhere, so that might be my problem.

Yes, it is not recommended to use the dev3-cdb branch. I believe this issue is not present for the dev3 branch (or dev2 or dev1) (at least, I cannot reproduce it). Let me know if switching to dev3 fixes your probem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants