mimalloc 3.0.10 crash in pthread_tsd_cleanup() when allocating C++ thread_local then shutting down on macOS
Using this test code, mimalloc 3.0.10 crashes on joining a thread:
#include <thread>
#include <cstdlib>
thread_local void* s_ptr = malloc(1);
int main()
{
std::thread thread([]() { free(s_ptr); });
thread.join();
free(s_ptr);
return 0;
}
The callstack looks like this:
main:
libsystem_kernel.dylib!__ulock_wait (Unknown Source:0)
libsystem_pthread.dylib!_pthread_join (Unknown Source:0)
libc++.1.dylib!std::__1::thread::join() (Unknown Source:0)
test!main (main.cpp:9)
start (Unknown Source:0)
thread:
dyld!mi_page_xthread_id (mimalloc-3.0.10/include/mimalloc/internal.h:723)
dyld!mi_free (mimalloc-3.0.10/src/free.c:187)
libsystem_pthread.dylib!_pthread_tsd_cleanup (Unknown Source:0)
libsystem_pthread.dylib!_pthread_exit (Unknown Source:0)
libsystem_pthread.dylib!_pthread_start (Unknown Source:0)
I'm on macOS 26.1 using this clang:
Apple clang version 17.0.0 (clang-1700.4.4.1)
Target: arm64-apple-darwin25.1.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
This crash does not occur for me when using mimalloc 2.2.2 or the default system allocator.
Please let me know if you need more info! I'd love to upgrade to 3.0.10 but this crash is preventing me from doing so.
I also wanted to mention that this seems to be an issue only on arm based macs. I just tried this on my Intel MacBook Pro on Sequioa 15.7.2 with this toolchain and it all seems to work fine:
Apple clang version 17.0.0 (clang-1700.4.4.1)
Target: x86_64-apple-darwin24.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
Thanks for the report. However, 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 this fixes your probem?
I used mimalloc 3.0.10 from the releases here. When I apply the fix from https://github.com/microsoft/mimalloc/pull/1178 the crash goes away on my arm based mac and I'm able to run my application normally. Definitely fixes the issue for me!
Thanks! Can you still try the latest dev3 and see if that also fixes the crash (I'm going to do a fresh release soon and it would be good to confirm this is not an issue). (and also, try to not use 3.0.x release from dev3-cdb -- these are internal only)
I just tried dev3 on commit 742a3e1d3d0e2adb444bbd29e83e037d09deccb4 which does not crash. But dev3-cdb on commit 156cebfbec73fcaf8464d8127b0285bc219db6ad does crash.