Commit 1615a17e authored by Müller, Felix's avatar Müller, Felix
Browse files

Fix invalid iterator access

parent 4394a565
......@@ -36,7 +36,7 @@ namespace AMDiS
public:
virtual ~ObserverInterface() = default;
virtual void update(Event e) = 0;
virtual void detach() = 0;
virtual void unset() = 0;
};
......@@ -65,8 +65,9 @@ namespace AMDiS
public:
virtual ~Notifier()
{
// Remove remaining pointers to this to avoid segfaults
for (ObserverInterface<Event>* o : observers_)
o->detach();
o->unset();
}
/// Call the \ref update method on all attached observers.
......@@ -109,7 +110,8 @@ namespace AMDiS
/// Destructor, detaches from the notifier
virtual ~Observer()
{
detach();
if (notifier_)
notifier_->detach(this);
}
/// Copy constructor. Attaches this to the copied notifier
......@@ -130,13 +132,11 @@ namespace AMDiS
return *this;
}
void detach() final
/// Set the Notifier* to nullptr. Used by the Notifer to avoid segfaults when destruction occurs
/// out of order.
void unset() final
{
if (notifier_)
{
notifier_->detach(this);
notifier_ = nullptr;
}
notifier_ = nullptr;
}
/// Implementation of the interface method \ref ObserverInterface::update.
......
Supports Markdown
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