Skip to content
Snippets Groups Projects
Commit 727c67b4 authored by Botond Baranyi's avatar Botond Baranyi
Browse files

Fixed infinite loop when creating references to an object in its destructor (bug 552011)


Change-Id: I17616dcccc69f05742c050c3ba4a2b686617be96
Signed-off-by: default avatarBotond Baranyi <botond.baranyi@ericsson.com>
parent 70a17e10
No related branches found
No related tags found
No related merge requests found
...@@ -22,12 +22,14 @@ ...@@ -22,12 +22,14 @@
class OBJECT { class OBJECT {
private: private:
size_t ref_count; 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(const OBJECT&); // copy disabled
OBJECT operator=(const OBJECT&); // assignment disabled OBJECT operator=(const OBJECT&); // assignment disabled
boolean operator==(const OBJECT&); // equality operator disabled boolean operator==(const OBJECT&); // equality operator disabled
public: public:
OBJECT(): ref_count(0) {} OBJECT(): ref_count(0), destructor(FALSE) {}
virtual ~OBJECT() { virtual ~OBJECT() {
if (ref_count != 0) { if (ref_count != 0) {
TTCN_error("Internal error: deleting an object with %lu reference(s) left.", ref_count); TTCN_error("Internal error: deleting an object with %lu reference(s) left.", ref_count);
...@@ -36,7 +38,11 @@ public: ...@@ -36,7 +38,11 @@ public:
void add_ref() { ++ref_count; } void add_ref() { ++ref_count; }
boolean remove_ref() { boolean remove_ref() {
--ref_count; --ref_count;
return ref_count == 0; if (destructor) {
return FALSE;
}
destructor = ref_count == 0;
return destructor;
} }
virtual void log() const { virtual void log() const {
TTCN_Logger::log_event_str("object: { }"); TTCN_Logger::log_event_str("object: { }");
......
...@@ -101,6 +101,10 @@ type class BaseClass runs on CT mtc CT system CT { ...@@ -101,6 +101,10 @@ type class BaseClass runs on CT mtc CT system CT {
finally { finally {
//pt.send(-1); //pt.send(-1);
log(m_var); log(m_var);
log(this);
log(this);
log(this);
log(this);
} }
type class SubClass extends BaseClass { type class SubClass extends BaseClass {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment