]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Limit DNS cache size
authorAttila Molnar <attilamolnar@hush.com>
Sat, 13 Feb 2016 18:23:07 +0000 (19:23 +0100)
committerAttila Molnar <attilamolnar@hush.com>
Sat, 13 Feb 2016 18:23:07 +0000 (19:23 +0100)
include/dns.h
src/dns.cpp

index de4bcf4223fb713273b3edc2a4a1243f67b35490..05df6f69cb3baeb1efb5ac747b120126bbc580dc 100644 (file)
@@ -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
         */
index ff823524c347f0fad7c865e6fb9fc7df1d960f99..3d3bc947fee2cfbee4f045e04b56b5eeb0730687 100644 (file)
@@ -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];