summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-07-14 11:43:17 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-07-14 11:43:17 +0000
commitccb1837a1481ed3d9048f2e4d0d5d6309f14d17d (patch)
treea0e0dea848b3af6f81cb72f5ff64a21d43214b1b
parent45216ce4311f7dbe6ec7c8227152017449ea3336 (diff)
Fix dns socket leak found in stable
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@4383 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r--include/users.h2
-rw-r--r--src/dns.cpp5
-rw-r--r--src/dnsqueue.cpp22
-rw-r--r--src/users.cpp9
4 files changed, 33 insertions, 5 deletions
diff --git a/include/users.h b/include/users.h
index 30fa937fb..641c33f01 100644
--- a/include/users.h
+++ b/include/users.h
@@ -393,6 +393,8 @@ class userrec : public connection
/** Thread used for threaded lookups
*/
pthread_t dnsthread;
+#else
+ int dns_fd;
#endif
};
diff --git a/src/dns.cpp b/src/dns.cpp
index e8b15c9bf..e3a32a745 100644
--- a/src/dns.cpp
+++ b/src/dns.cpp
@@ -702,6 +702,11 @@ void DNS::SetNS(const std::string &dnsserver)
DNS::~DNS()
{
+ if (this->myfd > -1)
+ {
+ log(DEBUG,"HA! An FD tried to sneak by unnoticed - freed it.");
+ dns_close(this->myfd);
+ }
}
bool DNS::ReverseLookup(const std::string &ip, bool ins)
diff --git a/src/dnsqueue.cpp b/src/dnsqueue.cpp
index ce0422fde..8c9dbbb75 100644
--- a/src/dnsqueue.cpp
+++ b/src/dnsqueue.cpp
@@ -5,8 +5,8 @@
* InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
* E-mail:
* <brain@chatspike.net>
- * <Craig@chatspike.net>
- *
+ * <Craig@chatspike.net>
+ *
* Written by Craig Edwards, Craig McLure, and others.
* This program is free but copyrighted software; see
* the file COPYING for details.
@@ -71,12 +71,14 @@ public:
if (usr)
{
resolver1.SetNS(std::string(Config->DNSServer));
- if (!resolver1.ReverseLookup(std::string(usr->host), true))
{
return false;
}
strlcpy(u,nick.c_str(),NICKMAX-1);
+#ifndef THREADED_DNS
+ usr->dns_fd = resolver1.GetFD();
+#endif
/* ASSOCIATE WITH DNS LOOKUP LIST */
if (resolver1.GetFD() != -1)
{
@@ -122,6 +124,9 @@ public:
WriteServ(usr->fd,"NOTICE Auth :*** Found your hostname");
}
usr->dns_done = true;
+#ifndef THREADED_DNS
+ usr->dns_fd = -1;
+#endif
return true;
}
}
@@ -132,6 +137,9 @@ public:
if (usr)
{
usr->dns_done = true;
+#ifndef THREADED_DNS
+ usr->dns_fd = -1;
+#endif
}
return true;
}
@@ -164,11 +172,16 @@ public:
return true;
}
}
- if (hostname != "")
+ if ((hostname != "") && (usr))
{
resolver2.ForwardLookup(hostname, true);
if (resolver2.GetFD() != -1)
+ {
dnslist[resolver2.GetFD()] = this;
+#ifndef THREADED_DNS
+ usr->dns_fd = resolver2.GetFD();
+#endif
+ }
}
}
}
@@ -270,3 +283,4 @@ void dns_poll(int fdcheck)
if (ServerInstance && ServerInstance->SE)
ServerInstance->SE->DelFd(fdcheck);
}
+
diff --git a/src/users.cpp b/src/users.cpp
index f455bb825..4918c417b 100644
--- a/src/users.cpp
+++ b/src/users.cpp
@@ -202,7 +202,9 @@ userrec::userrec()
invites.clear();
chans.resize(MAXCHANS);
memset(modes,0,sizeof(modes));
-
+#ifndef THREADED_DNS
+ dns_fd = -1;
+#endif
for (unsigned int n = 0; n < MAXCHANS; n++)
{
ucrec* x = new ucrec();
@@ -219,6 +221,11 @@ userrec::~userrec()
ucrec* x = (ucrec*)*n;
DELETE(x);
}
+ if (dns_fd > -1)
+ {
+ shutdown(dns_fd, 2);
+ close(dns_fd);
+ }
}
/* XXX - minor point, other *Host functions return a char *, this one creates it. Might be nice to be consistant? */