From 09c716ce117e3c89b4da7ab88f4caaefb43511b5 Mon Sep 17 00:00:00 2001 From: Attila Molnar Date: Sat, 13 Feb 2016 19:23:07 +0100 Subject: [PATCH] Limit DNS cache size --- include/dns.h | 4 ++++ src/dns.cpp | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/include/dns.h b/include/dns.h index de4bcf422..05df6f69c 100644 --- a/include/dns.h +++ b/include/dns.h @@ -302,6 +302,10 @@ class CoreExport DNS : public EventHandler */ static const int MAX_REQUEST_ID = 0xFFFF; + /** Maximum number of entries in cache + */ + static const unsigned int MAX_CACHE_SIZE = 1000; + /** * Currently cached items */ diff --git a/src/dns.cpp b/src/dns.cpp index ff823524c..3d3bc947f 100644 --- a/src/dns.cpp +++ b/src/dns.cpp @@ -1060,7 +1060,11 @@ void DNS::HandleEvent(EventType, int) ServerInstance->stats->statsDnsGood++; if (!this->GetCache(res.original.c_str())) + { + if (cache->size() >= MAX_CACHE_SIZE) + cache->clear(); this->cache->insert(std::make_pair(res.original.c_str(), CachedQuery(res.result, res.type, res.ttl))); + } Classes[res.id]->OnLookupComplete(res.result, res.ttl, false); delete Classes[res.id]; -- 2.39.2