From beec19951d84bc79d1b15e22b09137d8038f7ffe Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Sun, 5 Jul 2020 14:09:23 +0200 Subject: [PATCH] Candidate for fix. --- src/pya/pya/pyaObject.cc | 6 +++++- src/rba/rba/rbaInternal.cc | 6 +++++- testdata/ruby/basic_testcore.rb | 6 ++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/pya/pya/pyaObject.cc b/src/pya/pya/pyaObject.cc index c4f8f815c..11ee0be14 100644 --- a/src/pya/pya/pyaObject.cc +++ b/src/pya/pya/pyaObject.cc @@ -306,7 +306,11 @@ PYAObjectBase::detach () } } - detach_callbacks (); + // NOTE: m_owned = false might mean the C++ object is already destroyed. We must not + // modify in this case and without is_managed() there is no way of knowing the state. + if (m_owned) { + detach_callbacks (); + } m_obj = 0; m_const_ref = false; diff --git a/src/rba/rba/rbaInternal.cc b/src/rba/rba/rbaInternal.cc index 8a7ed7fc2..3ca0c0ea2 100644 --- a/src/rba/rba/rbaInternal.cc +++ b/src/rba/rba/rbaInternal.cc @@ -402,7 +402,11 @@ Proxy::detach () } } - clear_callbacks (); + // NOTE: m_owned = false might mean the C++ object is already destroyed. We must not + // modify in this case and without is_managed() there is no way of knowing the state. + if (m_owned) { + clear_callbacks (); + } m_self = Qnil; m_obj = 0; diff --git a/testdata/ruby/basic_testcore.rb b/testdata/ruby/basic_testcore.rb index ccacfe280..97e97e794 100644 --- a/testdata/ruby/basic_testcore.rb +++ b/testdata/ruby/basic_testcore.rb @@ -1402,6 +1402,12 @@ class Basic_TestClass < TestBase a._manage end + # Looks like Ruby is keeping the last A instance in some kind of cache: + # this will release it + a = RBA::A.new + a._destroy + a = nil + # makes sure the objects inside the block before are deleted GC.start