]> 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 16:58:50 +0000 (19:58 +0300)
* 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 ea0e9705aa621f7290ae6f652c6abd3638f8c64e..1ed36be56e8dddfed509c02c4cfc77408635dbb5 100644 (file)
@@ -416,7 +416,9 @@ inline void gc::operator delete(void* obj)
 
 inline gc_cleanup::~gc_cleanup()
 {
-  GC_register_finalizer_ignore_self(GC_base(this), 0, 0, 0, 0);
+  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)