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: Botond Baranyi's avatarBotond Baranyi <botond.baranyi@ericsson.com>
parent 70a17e10
......@@ -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: { }");
......
......@@ -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 {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment