From da7cba69389c3c90cb9e02ac2d18f62d3e83a944 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Tue, 19 Jan 2021 01:43:24 +0000 Subject: [PATCH 1/1] Fix the DNS socket not being closed when core_dns is unloaded. --- src/coremods/core_dns.cpp | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/coremods/core_dns.cpp b/src/coremods/core_dns.cpp index 11c2c823c..aec413207 100644 --- a/src/coremods/core_dns.cpp +++ b/src/coremods/core_dns.cpp @@ -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); -- 2.39.2