From: Ivan Maidanski Date: Fri, 23 Jun 2017 06:13:15 +0000 (+0300) Subject: Ensure GC initialized when atfork_prepare is called by client X-Git-Tag: v8.0.0~665 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=dc488239f1b4b3e7c4322736aab4fe4f0139abb4;p=gc Ensure GC initialized when atfork_prepare is called by client Otherwise, if THREAD_LOCAL_ALLOC, GC_remove_all_threads_but_me would not find the current thread descriptor in GC_threads. * pthread_support.c [CAN_HANDLE_FORK] (GC_atfork_prepare): Call GC_init if not GC_is_initialized. * win32_threads.c [CAN_HANDLE_FORK] (GC_atfork_prepare): Likewise. --- diff --git a/pthread_support.c b/pthread_support.c index e406322e..effd850d 100644 --- a/pthread_support.c +++ b/pthread_support.c @@ -1061,6 +1061,7 @@ static void fork_child_proc(void) /* Routines for fork handling by client (no-op if pthread_atfork works). */ GC_API void GC_CALL GC_atfork_prepare(void) { + if (!EXPECT(GC_is_initialized, TRUE)) GC_init(); # if defined(GC_DARWIN_THREADS) && defined(MPROTECT_VDB) if (GC_dirty_maintained) { GC_ASSERT(0 == GC_handle_fork); diff --git a/win32_threads.c b/win32_threads.c index 55658416..ae643ba0 100644 --- a/win32_threads.c +++ b/win32_threads.c @@ -1110,6 +1110,7 @@ GC_API void * GC_CALL GC_call_with_gc_active(GC_fn_type fn, /* Routines for fork handling by client (no-op if pthread_atfork works). */ GC_API void GC_CALL GC_atfork_prepare(void) { + if (!EXPECT(GC_is_initialized, TRUE)) GC_init(); if (GC_handle_fork <= 0) fork_prepare_proc(); }