]> granicus.if.org Git - gc/commitdiff
Fix gc_cleanup destructor for non-heap objects (gc_cpp)
authorIvan Maidanski <ivmai@mail.ru>
Fri, 9 Dec 2016 23:19:32 +0000 (02:19 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Mon, 6 Feb 2017 18:43:05 +0000 (21:43 +0300)
(Cherry-pick commit ed19165 from 'release-7_6' branch.)

* include/gc_cpp.h (gc_cleanup::~gc_cleanup): If GC_base(this) returns
null (could be if the object is not allocated dynamically) then do not
call GC_register_finalizer_ignore_self.

include/gc_cpp.h

index 2e4aa1b4f5e63e21be26ca8fba8b2199eaf36bae..4f25dddfec83abbcb3818f1d11d668930c28b78d 100644 (file)
@@ -361,8 +361,11 @@ inline void gc::operator delete( void* obj ) {
 # endif
 #endif /* GC_OPERATOR_NEW_ARRAY */
 
-inline gc_cleanup::~gc_cleanup() {
-    GC_register_finalizer_ignore_self( GC_base(this), 0, 0, 0, 0 );
+inline gc_cleanup::~gc_cleanup()
+{
+  void* base = GC_base(this);
+  if (0 == base) return; // Non-heap object.
+  GC_register_finalizer_ignore_self(base, 0, 0, 0, 0);
 }
 
 inline void GC_CALLBACK gc_cleanup::cleanup( void* obj, void* displ ) {