From c54da4351993e270e95c370e54d8c8f818fb11dc Mon Sep 17 00:00:00 2001 From: TheCoconutChef Date: Wed, 18 Sep 2024 13:39:10 -0400 Subject: [PATCH] revert to index based notify loop 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::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. --- lager/detail/nodes.hpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lager/detail/nodes.hpp b/lager/detail/nodes.hpp index 0748259..633be49 100644 --- a/lager/detail/nodes.hpp +++ b/lager/detail/nodes.hpp @@ -235,8 +235,9 @@ class reader_node : public observable_reader_node 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;