Fix SIGSEGV in GC_is_marked when gc_cleanup is used in leak-finding mode
authorIvan Maidanski <ivmai@mail.ru>
Fri, 14 Jul 2017 08:11:13 +0000 (11:11 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Fri, 14 Jul 2017 08:11:13 +0000 (11:11 +0300)
Issue #162 (bdwgc).

Now finalizers and disappearing links registration is a no-op in case
of the leak-finding mode.

*  finalize.c (GC_register_disappearing_link_inner): Do nothing (return
GC_UNIMPLEMENTED) if GC_find_leak.
* finalize.c (GC_register_finalizer_inner): Do nothing if GC_find_leak.
* include/gc.h (GC_find_leak): More verbose comment.
* include/gc.h (GC_debug_register_finalizer,
GC_general_register_disappearing_link): Document the case of
GC_find_leak.

finalize.c
include/gc.h

index 4b65279..bd297a9 100644 (file)
@@ -152,6 +152,7 @@ STATIC int GC_register_disappearing_link_inner(
     struct disappearing_link * new_dl;
     DCL_LOCK_STATE;
 
+    if (EXPECT(GC_find_leak, FALSE)) return GC_UNIMPLEMENTED;
     LOCK();
     GC_ASSERT(obj != NULL && GC_base_C(obj) == obj);
     if (dl_hashtbl -> log_size == -1
@@ -647,6 +648,7 @@ STATIC void GC_register_finalizer_inner(void * obj,
     hdr *hhdr = NULL; /* initialized to prevent warning. */
     DCL_LOCK_STATE;
 
+    if (EXPECT(GC_find_leak, FALSE)) return;
     LOCK();
     if (log_fo_table_size == -1
         || GC_fo_entries > ((word)1 << log_fo_table_size)) {
index a6a6767..ec0e86f 100644 (file)
@@ -174,9 +174,10 @@ GC_API GC_on_collection_event_proc GC_CALL GC_get_on_collection_event(void);
 #endif
 
 GC_API GC_ATTR_DEPRECATED int GC_find_leak;
-                        /* Do not actually garbage collect, but simply  */
+                        /* Set to true to turn on the leak-finding mode */
+                        /* (do not actually garbage collect, but simply */
                         /* report inaccessible memory that was not      */
-                        /* deallocated with GC_free.  Initial value     */
+                        /* deallocated with GC_FREE).  Initial value    */
                         /* is determined by FIND_LEAK macro.            */
                         /* The value should not typically be modified   */
                         /* after GC initialization (and, thus, it does  */
@@ -994,6 +995,7 @@ GC_API void GC_CALL GC_debug_register_finalizer(void * /* obj */,
         /* be avoided, or broken by disappearing links.         */
         /* All but the last finalizer registered for an object  */
         /* is ignored.                                          */
+        /* No-op in the leak-finding mode.                      */
         /* Finalization may be removed by passing 0 as fn.      */
         /* Finalizers are implicitly unregistered when they are */
         /* enqueued for finalization (i.e. become ready to be   */
@@ -1131,6 +1133,7 @@ GC_API int GC_CALL GC_general_register_disappearing_link(void ** /* link */,
         /* explicitly deallocate the object containing link.    */
         /* Explicit deallocation of obj may or may not cause    */
         /* link to eventually be cleared.                       */
+        /* No-op in the leak-finding mode.                      */
         /* This function can be used to implement certain types */
         /* of weak pointers.  Note, however, this generally     */
         /* requires that the allocation lock is held (see       */
@@ -1142,7 +1145,8 @@ GC_API int GC_CALL GC_general_register_disappearing_link(void ** /* link */,
         /* succeeded (a new link is registered), GC_DUPLICATE   */
         /* if link was already registered (with some object),   */
         /* GC_NO_MEMORY if registration failed for lack of      */
-        /* memory (and GC_oom_fn did not handle the problem).   */
+        /* memory (and GC_oom_fn did not handle the problem),   */
+        /* GC_UNIMPLEMENTED if GC_find_leak is true.            */
 
 GC_API int GC_CALL GC_move_disappearing_link(void ** /* link */,
                                              void ** /* new_link */)