summaryrefslogtreecommitdiff
path: root/src/modules
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2005-04-20 02:48:12 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2005-04-20 02:48:12 +0000
commit1e4d37149c3c44a479dc3440a650e433c7f1b9c2 (patch)
tree5001350220a145beee03f9f048aa01094c128f53 /src/modules
parent4f62aeb27ebf1cb142d34121defe1a47e8a17444 (diff)
Added OnUserDisconnect method to modules.* to fix fd leak in m_ident.cpp
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@1134 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src/modules')
-rw-r--r--src/modules/m_ident.cpp39
1 files changed, 34 insertions, 5 deletions
diff --git a/src/modules/m_ident.cpp b/src/modules/m_ident.cpp
index 90a6f448a..bf4e66a6c 100644
--- a/src/modules/m_ident.cpp
+++ b/src/modules/m_ident.cpp
@@ -69,6 +69,16 @@ class RFC1413
bool timeout; // true if we've timed out and should bail
public:
+ ~RFC1413()
+ {
+ if (this->fd != -1)
+ {
+ shutdown(this->fd,2);
+ close(this->fd);
+ this->fd = -1;
+ }
+ }
+
// establish an ident connection, maxtime is the time to spend trying
// returns true if successful, false if something was catastrophically wrong.
// note that failed connects are not reported here but detected in RFC1413::Poll()
@@ -100,8 +110,9 @@ class RFC1413
{
// ... so that error isnt fatal, like the rest.
Srv->Log(DEBUG,"Ident: connect failed for: "+std::string(user->ip));
+ shutdown(this->fd,2);
close(this->fd);
- shutdown(this->fd,2);
+ this->fd = -1;
return false;
}
}
@@ -120,8 +131,9 @@ class RFC1413
{
timeout = true;
Srv->SendServ(u->fd,"NOTICE "+std::string(u->nick)+" :*** Could not find your ident, using "+std::string(u->ident)+" instead.");
- close(this->fd);
shutdown(this->fd,2);
+ close(this->fd);
+ this->fd = -1;
return false;
}
pollfd polls;
@@ -151,8 +163,9 @@ class RFC1413
if ((getsockname(this->u->fd,(sockaddr*)&sock_us,&uslen) || getpeername(this->u->fd, (sockaddr*)&sock_them, &themlen)))
{
Srv->Log(DEBUG,"Ident: failed to get socket names, bailing to state 3");
+ shutdown(this->fd,2);
close(this->fd);
- shutdown(this->fd,2);
+ this->fd = -1;
state = IDENT_STATE_DONE;
}
else
@@ -173,8 +186,9 @@ class RFC1413
// 6195, 23 : ERROR : NO-USER
ibuf[nrecv] = '\0';
Srv->Log(DEBUG,"Received ident response: "+std::string(ibuf));
- close(this->fd);
shutdown(this->fd,2);
+ close(this->fd);
+ this->fd = -1;
char* savept;
char* section = strtok_r(ibuf,":",&savept);
while (section)
@@ -209,6 +223,9 @@ class RFC1413
}
break;
case IDENT_STATE_DONE:
+ shutdown(this->fd,2);
+ close(this->fd);
+ this->fd = -1;
Srv->Log(DEBUG,"Ident lookup is complete!");
break;
default:
@@ -223,7 +240,7 @@ class RFC1413
bool Done()
{
- return ((state == 3) || (timeout == true));
+ return ((state == IDENT_STATE_DONE) || (timeout == true));
}
};
@@ -297,6 +314,18 @@ class ModuleIdent : public Module
}
return true;
}
+
+ virtual void OnUserDisconnect(userrec* user)
+ {
+ // when the user quits tidy up any ident lookup they have pending to keep things tidy
+ // and to prevent a memory and FD leaks
+ RFC1413* ident = (RFC1413*)user->GetExt("ident_data");
+ if (ident)
+ {
+ delete ident;
+ user->Shrink("ident_data");
+ }
+ }
virtual ~ModuleIdent()
{