diff --git a/core/OOP.hh b/core/OOP.hh index 52f2c223bfc05be35d7beede289f650c0ec70007..4dced3ffa091f792d8702dc2fa4e1af16ade0927 100644 --- a/core/OOP.hh +++ b/core/OOP.hh @@ -22,12 +22,14 @@ class OBJECT { private: size_t ref_count; + boolean destructor; // true, if the destructor is currently running; + // also makes sure the object is not deleted again when inside the destructor OBJECT(const OBJECT&); // copy disabled OBJECT operator=(const OBJECT&); // assignment disabled boolean operator==(const OBJECT&); // equality operator disabled public: - OBJECT(): ref_count(0) {} + OBJECT(): ref_count(0), destructor(FALSE) {} virtual ~OBJECT() { if (ref_count != 0) { TTCN_error("Internal error: deleting an object with %lu reference(s) left.", ref_count); @@ -36,7 +38,11 @@ public: void add_ref() { ++ref_count; } boolean remove_ref() { --ref_count; - return ref_count == 0; + if (destructor) { + return FALSE; + } + destructor = ref_count == 0; + return destructor; } virtual void log() const { TTCN_Logger::log_event_str("object: { }"); diff --git a/regression_test/oop/oop.ttcn b/regression_test/oop/oop.ttcn index d16a79e01271207a359d84e672b2b472815680d7..ffd2a20151dfc6c24abcee135e2388d5c9cd26a9 100644 --- a/regression_test/oop/oop.ttcn +++ b/regression_test/oop/oop.ttcn @@ -101,6 +101,10 @@ type class BaseClass runs on CT mtc CT system CT { finally { //pt.send(-1); log(m_var); + log(this); + log(this); + log(this); + log(this); } type class SubClass extends BaseClass {