From 40348b24e10b7335ae55d6797749ccd525b5226d Mon Sep 17 00:00:00 2001 From: Jason Rhinelander Date: Mon, 31 Oct 2022 21:22:13 -0300 Subject: [PATCH] Fix crash on unbound cleanup We need to make a copy here because (see comment). --- llarp/dns/server.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/llarp/dns/server.cpp b/llarp/dns/server.cpp index d94186aab..4a0d22da4 100644 --- a/llarp/dns/server.cpp +++ b/llarp/dns/server.cpp @@ -427,9 +427,12 @@ namespace llarp::dns if (not m_Pending.empty()) { log::debug(logcat, "cancelling {} pending queries", m_Pending.size()); - for (const auto& query : m_Pending) + // We must copy because Cancel does a loop call to remove itself, but since we are + // already in the main loop it happens immediately, which would invalidate our iterator + // if we were looping through m_Pending at the time. + auto copy = m_Pending; + for (const auto& query : copy) query->Cancel(); - m_Pending.clear(); } } }