Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
amdis
amdis-core
Commits
1615a17e
Commit
1615a17e
authored
Jan 07, 2020
by
Müller, Felix
Browse files
Fix invalid iterator access
parent
4394a565
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/amdis/Observer.hpp
View file @
1615a17e
...
...
@@ -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.
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment