From 08acde5da0d2f0c742be3f5c387737e069fd3891 Mon Sep 17 00:00:00 2001 From: Javier Blazquez Date: Sun, 22 Dec 2024 18:50:09 -0800 Subject: [PATCH] fix crash on exit on Android with destroy_on_exit --- src/init.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/init.c b/src/init.c index 68a1d7e2..8eaeb174 100644 --- a/src/init.c +++ b/src/init.c @@ -663,9 +663,6 @@ void mi_cdecl _mi_process_done(void) { if (process_done) return; process_done = true; - // release any thread specific resources and ensure _mi_thread_done is called on all but the main thread - _mi_prim_thread_done_auto_done(); - #ifndef MI_SKIP_COLLECT_ON_EXIT #if (MI_DEBUG || !defined(MI_SHARED_LIB)) // free all memory if possible on process exit. This is not needed for a stand-alone process @@ -684,6 +681,10 @@ void mi_cdecl _mi_process_done(void) { _mi_arena_unsafe_destroy_all(); } + // release any thread specific resources and ensure _mi_thread_done is called on all but the main thread + // this must be done after _mi_heap_unsafe_destroy_all, which accesses the default heap + _mi_prim_thread_done_auto_done(); + if (mi_option_is_enabled(mi_option_show_stats) || mi_option_is_enabled(mi_option_verbose)) { mi_stats_print(NULL); }