From: Ivan Maidanski Date: Fri, 14 Jul 2017 08:11:13 +0000 (+0300) Subject: Fix SIGSEGV in GC_is_marked when gc_cleanup is used in leak-finding mode X-Git-Tag: v7.6.2~113 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e5fc6686d307ec4c4c85497149a8ba7b0f0045fa;p=gc Fix SIGSEGV in GC_is_marked when gc_cleanup is used in leak-finding mode 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. --- diff --git a/finalize.c b/finalize.c index 4b652790..bd297a9c 100644 --- a/finalize.c +++ b/finalize.c @@ -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)) { diff --git a/include/gc.h b/include/gc.h index a0231576..d4fbfb87 100644 --- a/include/gc.h +++ b/include/gc.h @@ -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 */)