From 17ba47558cd777d28029c0cb0b0c1b7d28ad47e3 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 26 Jun 2023 11:22:12 +0200 Subject: [PATCH] LibWeb: Make a copy of Document's DocumentObserver set when iterating The observer callbacks can do all kinds of things, so let's not be in the middle of iterating the set in case someone decides to mutate it. Fixes a crash when loading https://lichess.org/ --- Userland/Libraries/LibWeb/DOM/Document.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp index c413a7b309..48ee500b05 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.cpp +++ b/Userland/Libraries/LibWeb/DOM/Document.cpp @@ -1752,7 +1752,8 @@ void Document::completely_finish_loading() }); } - for (auto& document_observer : m_document_observers) { + auto observers_to_notify = m_document_observers.values(); + for (auto& document_observer : observers_to_notify) { if (document_observer->document_fully_loaded) document_observer->document_fully_loaded(); } @@ -2627,7 +2628,8 @@ void Document::did_stop_being_active_document_in_browsing_context(Badgedocument_became_inactive) document_observer->document_became_inactive(); }