]> granicus.if.org Git - gc/commitdiff
Fix 'collecting from unknown thread' abort in leak-finding mode
authorIvan Maidanski <ivmai@mail.ru>
Fri, 8 Jun 2018 20:41:22 +0000 (23:41 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Tue, 17 Jul 2018 06:03:31 +0000 (09:03 +0300)
(a cherry-pick of commit 8e646005 from 'master')

* include/private/gc_priv.h [GC_PTHREADS && !GC_WIN32_THREADS]
(GC_in_thread_creation): Move variable declaration from
pthread_support.h.
* misc.c [!DONT_USE_ATEXIT && GC_PTHREADS && !GC_WIN32_THREADS]
(GC_exit_check): Set GC_in_thread_creation to TRUE before GC_gcollect
call.

include/private/gc_priv.h
include/private/pthread_support.h
misc.c

index 88164dd8e8caebb07da6eca51a7e4caea75bbb40..dfd19cc683036a0f186cd3db08c9e8eeec007c1c 100644 (file)
@@ -1854,6 +1854,13 @@ GC_INNER GC_bool GC_try_to_collect_inner(GC_stop_func f);
 #define GC_gcollect_inner() \
                 (void)GC_try_to_collect_inner(GC_never_stop_func)
 
+#if defined(GC_PTHREADS) && !defined(GC_WIN32_THREADS)
+  GC_EXTERN GC_bool GC_in_thread_creation;
+        /* We may currently be in thread creation or destruction.       */
+        /* Only set to TRUE while allocation lock is held.              */
+        /* When set, it is OK to run GC from unknown thread.            */
+#endif
+
 GC_EXTERN GC_bool GC_is_initialized; /* GC_init() has been run. */
 
 #if defined(MSWIN32) || defined(MSWINCE)
index c4e424d22137f0ccbb3901617c47466dae2298b9..69b4742eb276734d0b17972e209885e17037aff8 100644 (file)
@@ -123,11 +123,6 @@ GC_EXTERN GC_bool GC_thr_initialized;
 
 GC_INNER GC_thread GC_lookup_thread(pthread_t id);
 
-GC_EXTERN GC_bool GC_in_thread_creation;
-        /* We may currently be in thread creation or destruction.       */
-        /* Only set to TRUE while allocation lock is held.              */
-        /* When set, it is OK to run GC from unknown thread.            */
-
 #ifdef NACL
   GC_EXTERN __thread GC_thread GC_nacl_gc_thread_self;
   GC_INNER void GC_nacl_initialize_gc_thread(void);
diff --git a/misc.c b/misc.c
index c413a9897dd03022c81ec39870075193ea1a71b4..ea629b7778c11258daf58fb0adf91f2996225247 100644 (file)
--- a/misc.c
+++ b/misc.c
@@ -744,7 +744,13 @@ GC_INNER GC_bool GC_is_initialized = FALSE;
   STATIC void GC_exit_check(void)
   {
     if (GC_find_leak) {
-      GC_gcollect();
+#     if defined(GC_PTHREADS) && !defined(GC_WIN32_THREADS)
+        GC_in_thread_creation = TRUE; /* OK to collect from unknown thread. */
+        GC_gcollect();
+        GC_in_thread_creation = FALSE;
+#     else
+        GC_gcollect();
+#     endif
     }
   }
 #endif