Skip to content

Commit

Permalink
revert to index based notify loop
Browse files Browse the repository at this point in the history
This fixes an issue in which calls to link occurring during notification
would invalidate the iterators of the structured for loop. Calling link
as a result of a reader<T>::watch callback can occur quite naturally.

By using the size of the children vector at the point at which the for
loop is initiated, and by using the [] operator in order to access the
children within the vector, the issue is avoided.
  • Loading branch information
TheCoconutChef committed Sep 18, 2024
1 parent 3f68361 commit c54da43
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lager/detail/nodes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,9 @@ class reader_node : public observable_reader_node<T>
bool garbage = false;

this->observers()(last_);
for (auto& wchild : this->children()) {
if (auto child = wchild.lock()) {
const auto& children = this->children();
for (size_t i = 0, size = children.size(); i < size; ++i) {
if (auto child = children[i].lock()) {
child->notify();
} else {
garbage = true;
Expand Down

0 comments on commit c54da43

Please sign in to comment.