Fix crash on unbound cleanup

We need to make a copy here because (see comment).
This commit is contained in:
Jason Rhinelander 2022-10-31 21:22:13 -03:00 committed by Jeff Becker
parent b8678a767e
commit 40348b24e1
No known key found for this signature in database
GPG Key ID: 025C02EE3A092F2D
1 changed files with 5 additions and 2 deletions

View File

@ -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();
}
}
}