summaryrefslogtreecommitdiff
path: root/src/dns.cpp
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-07-20 18:02:09 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-07-20 18:02:09 +0000
commit6bfae0cd735052b91151f8ffc56808d090683483 (patch)
treeb89b421bd263613c9c63e7d9dbf5671f703be591 /src/dns.cpp
parent3a7023f2c595d14778b3f1f7e53d3914698dd500 (diff)
Fixed, no longer a memory leak (Thread leak)
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@4465 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src/dns.cpp')
-rw-r--r--src/dns.cpp68
1 files changed, 51 insertions, 17 deletions
diff --git a/src/dns.cpp b/src/dns.cpp
index a8ed78cb6..f8433683d 100644
--- a/src/dns.cpp
+++ b/src/dns.cpp
@@ -475,6 +475,9 @@ char* DNS::dns_getresult_s(const int cfd, char *res) { /* retrieve result of DNS
if (n_iter == connections.end())
{
log(DEBUG,"DNS: got a response for a query we didnt send with fd=%d",cfd);
+#ifdef THREADED_DNS
+ pthread_mutex_unlock(&connmap_lock);
+#endif
return NULL;
}
else
@@ -879,34 +882,63 @@ void* dns_task(void* arg)
int thisfd = u->fd;
log(DEBUG,"DNS thread for user %s",u->nick);
- DNS dns1;
- DNS dns2;
+ DNS dns1(Config->DNSServer);
+ DNS dns2(Config->DNSServer);
std::string host;
std::string ip;
+ int iterations = 0;
+
+ log(DEBUG,"Thread loc 1");
if (dns1.ReverseLookup(inet_ntoa(u->ip4),false))
{
- while (!dns1.HasResult())
+ log(DEBUG,"Thread loc 2");
+ /* FIX: Dont make these infinite! */
+ while ((!dns1.HasResult()) && (++iterations < 20))
usleep(100);
- host = dns1.GetResult();
- if (host != "")
+
+ log(DEBUG,"Thread loc 3");
+ if (iterations < 20)
{
- if (dns2.ForwardLookup(host, false))
+ log(DEBUG,"Thread loc 4");
+ if (dns1.GetFD() != -1)
{
- while (!dns2.HasResult())
- usleep(100);
- ip = dns2.GetResultIP();
- if (ip == std::string(inet_ntoa(u->ip4)))
+ host = dns1.GetResult();
+ if (host != "")
{
- if (host.length() < 65)
+ log(DEBUG,"Thread loc 5");
+ if (dns2.ForwardLookup(host, false))
{
- if ((fd_ref_table[thisfd] == u) && (fd_ref_table[thisfd]))
+ iterations = 0;
+ while ((!dns2.HasResult()) && (++iterations < 20))
+ usleep(100);
+
+ log(DEBUG,"Thread loc 6");
+ if (iterations < 20)
{
- if (!u->dns_done)
+ if (dns2.GetFD() != -1)
{
- strcpy(u->host,host.c_str());
- if ((fd_ref_table[thisfd] == u) && (fd_ref_table[thisfd]))
+ log(DEBUG,"Thread loc 7");
+ ip = dns2.GetResultIP();
+ if (ip == std::string(inet_ntoa(u->ip4)))
{
- strcpy(u->dhost,host.c_str());
+ log(DEBUG,"Thread loc 8");
+ if (host.length() < 65)
+ {
+ log(DEBUG,"Thread loc 9");
+ if ((fd_ref_table[thisfd] == u) && (fd_ref_table[thisfd]))
+ {
+ log(DEBUG,"Thread loc 10");
+ if (!u->dns_done)
+ {
+ log(DEBUG,"Thread loc 11");
+ strcpy(u->host,host.c_str());
+ if ((fd_ref_table[thisfd] == u) && (fd_ref_table[thisfd]))
+ {
+ strcpy(u->dhost,host.c_str());
+ }
+ }
+ }
+ }
}
}
}
@@ -915,9 +947,11 @@ void* dns_task(void* arg)
}
}
}
+ log(DEBUG,"Thread loc 12");
if ((fd_ref_table[thisfd] == u) && (fd_ref_table[thisfd]))
u->dns_done = true;
- pthread_exit(0);
+ log(DEBUG,"THREAD EXIT");
+ return NULL;
}
#endif