Release each thread's allocator heap at DLL_THREAD_DETACH. * * Doing this from the thread wrapper instead crashes: the wrapper returns * before the CRT's own thread teardown, and abandoning the heap there raced * with frees still in flight (daemon_ipc_wait_forever_is_interruptible * segfaulted, rc=139, reproducibly and only with the release enabled). A TLS * callback is the mechanism mimallo
| 81 | * CBM_MI_THREAD_DONE=0 disables it, so one binary can demonstrate both |
| 82 | * behaviours rather than requiring a rebuild to establish causality. */ |
| 83 | static bool thread_release_heap_enabled(void) { |
| 84 | static int state = -1; |
| 85 | if (state < 0) { |
| 86 | char buf[CBM_SZ_16]; |
| 87 | state = |
| 88 | (cbm_safe_getenv("CBM_MI_THREAD_DONE", buf, sizeof(buf), NULL) != NULL && buf[0] == '0') |
| 89 | ? 0 |
| 90 | : 1; |
| 91 | } |
| 92 | return state == 1; |
| 93 | } |
| 94 | |
| 95 | static void NTAPI cbm_thread_detach_callback(PVOID handle, DWORD reason, PVOID reserved) { |
| 96 | (void)handle; |
no test coverage detected