From 12c53148635e5a7a7c69931d0cf49a7ffb1f3e1a Mon Sep 17 00:00:00 2001 From: Adam Date: Thu, 11 Nov 2010 19:24:41 -0500 Subject: [PATCH] Fixed possible unsafe iteration when purging dns cache, and fixed the dns cache to not expire all of the records for specific hosts if the records have different TTLs (cherry picked from commit 736df4bd98b952aad459fdf7914735e88f97c4b2) --- src/dns.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/dns.cpp b/src/dns.cpp index e587cc330..5bdd2a4eb 100644 --- a/src/dns.cpp +++ b/src/dns.cpp @@ -557,15 +557,16 @@ void DNSManager::Tick(time_t now) { Log(LOG_DEBUG_2) << "Resolver: Purging DNS cache"; - for (std::multimap::iterator it = this->cache.begin(), it_end = this->cache.end(); it != it_end;) + for (std::multimap::iterator it = this->cache.begin(), it_next; it != this->cache.end(); it = it_next) { Anope::string host = it->first; DNSRecord *req = it->second; - ++it; + it_next = it; + ++it_next; if (req->created + req->ttl < now) { - this->cache.erase(host); + this->cache.erase(it); delete req; } }