From e68f2c14796af42782400d4d4f982edbcb4832b9 Mon Sep 17 00:00:00 2001 From: Daan Leijen Date: Fri, 23 Dec 2022 13:02:16 -0800 Subject: [PATCH 1/2] fix recursion issue on exit on windows, #672 --- src/init.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/init.c b/src/init.c index b5a98403..11c66a67 100644 --- a/src/init.c +++ b/src/init.c @@ -350,7 +350,11 @@ static void _mi_thread_done(mi_heap_t* default_heap); #endif static DWORD mi_fls_key = (DWORD)(-1); static void NTAPI mi_fls_done(PVOID value) { - if (value!=NULL) _mi_thread_done((mi_heap_t*)value); + mi_heap_t* heap = (mi_heap_t*)value; + if (heap != NULL) { + _mi_thread_done(heap); + FlsSetValue(mi_fls_key, NULL); // prevent recursion as _mi_thread_done may set it back to the main heap, issue #672 + } } #elif defined(MI_USE_PTHREADS) // use pthread local storage keys to detect thread ending From 9adb032e9c5941f4fac941bcda234e86b3e4e95a Mon Sep 17 00:00:00 2001 From: Daan Leijen Date: Fri, 23 Dec 2022 13:04:53 -0800 Subject: [PATCH 2/2] test non-default heap --- test/main-override-static.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/main-override-static.c b/test/main-override-static.c index fcdea4d3..bf1cc416 100644 --- a/test/main-override-static.c +++ b/test/main-override-static.c @@ -42,6 +42,9 @@ int main() { char* s = strdup("hello\n"); free(p2); + mi_heap_t* h = mi_heap_new(); + mi_heap_set_default(h); + p2 = malloc(16); p1 = realloc(p1, 32); free(p1); @@ -58,6 +61,7 @@ int main() { //mi_stats_print(NULL); // test_process_info(); + return 0; }