]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Fix the DNS socket not being closed when core_dns is unloaded.
authorSadie Powell <sadie@witchery.services>
Tue, 19 Jan 2021 01:43:24 +0000 (01:43 +0000)
committerSadie Powell <sadie@witchery.services>
Tue, 19 Jan 2021 01:43:52 +0000 (01:43 +0000)
src/coremods/core_dns.cpp

index 11c2c823c890b785641c22459b7734ad21c94ff6..aec4132074cf8d9c50c3eb86994e2eb7b0feec2a 100644 (file)
@@ -409,6 +409,19 @@ class MyManager : public Manager, public Timer, public EventHandler
                this->cache[r.question] = r;
        }
 
+       void Close()
+       {
+               // Shutdown the socket if it exists.
+               if (HasFd())
+               {
+                       SocketEngine::Shutdown(this, 2);
+                       SocketEngine::Close(this);
+               }
+
+               // Remove all entries from the cache.
+               cache.clear();
+       }
+
  public:
        DNS::Request* requests[MAX_REQUEST_ID+1];
 
@@ -423,6 +436,7 @@ class MyManager : public Manager, public Timer, public EventHandler
        ~MyManager()
        {
                // Ensure Process() will fail for new requests
+               Close();
                unloading = true;
 
                for (unsigned int i = 0; i <= MAX_REQUEST_ID; ++i)
@@ -703,23 +717,15 @@ class MyManager : public Manager, public Timer, public EventHandler
 
        void Rehash(const std::string& dnsserver, std::string sourceaddr, unsigned int sourceport)
        {
-               if (this->HasFd())
-               {
-                       SocketEngine::Shutdown(this, 2);
-                       SocketEngine::Close(this);
-
-                       // Remove all entries from the cache.
-                       cache.clear();
-               }
-
                irc::sockets::aptosa(dnsserver, DNS::PORT, myserver);
 
                /* Initialize mastersocket */
+               Close();
                int s = socket(myserver.family(), SOCK_DGRAM, 0);
                this->SetFd(s);
 
                /* Have we got a socket? */
-               if (this->GetFd() != -1)
+               if (this->HasFd())
                {
                        SocketEngine::SetReuse(s);
                        SocketEngine::NonBlocking(s);