Skip to content

mimalloc 3.0.10 crash in pthread_tsd_cleanup() when allocating C++ thread_local then shutting down on macOS #1177

@unpacklo

Description

@unpacklo

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions