diff options
author | Sadie Powell <sadie@witchery.services> | 2020-02-19 18:00:36 +0000 |
---|---|---|
committer | Sadie Powell <sadie@witchery.services> | 2020-02-20 13:31:53 +0000 |
commit | 89f36a6f1c13465cebe56ee1e12fec1dec40679a (patch) | |
tree | a047ed5b5c6b2492e674e475b44c6c35b4e24301 /src/modules | |
parent | 327bacd3687f307a5f8586856a94b16c9e4370bf (diff) |
Fix a memory leak in the httpd module when sockets are closed late.
Diffstat (limited to 'src/modules')
-rw-r--r-- | src/modules/m_httpd.cpp | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/src/modules/m_httpd.cpp b/src/modules/m_httpd.cpp index bdb1d50fc..978a60ab7 100644 --- a/src/modules/m_httpd.cpp +++ b/src/modules/m_httpd.cpp @@ -95,7 +95,7 @@ class HttpServerSocket : public BufferedSocket, public Timer, public insp::intru { if (!messagecomplete) { - AddToCull(); + Close(); return false; } @@ -229,7 +229,7 @@ class HttpServerSocket : public BufferedSocket, public Timer, public insp::intru // IOHook may have errored if (!getError().empty()) { - AddToCull(); + Close(); return; } } @@ -244,9 +244,19 @@ class HttpServerSocket : public BufferedSocket, public Timer, public insp::intru sockets.erase(this); } + void Close() CXX11_OVERRIDE + { + if (waitingcull || !HasFd()) + return; + + waitingcull = true; + BufferedSocket::Close(); + ServerInstance->GlobalCulls.AddItem(this); + } + void OnError(BufferedSocketError) CXX11_OVERRIDE { - AddToCull(); + Close(); } void SendHTTPError(unsigned int response) @@ -315,7 +325,7 @@ class HttpServerSocket : public BufferedSocket, public Timer, public insp::intru { SendHeaders(s.length(), response, *hheaders); WriteData(s); - Close(true); + BufferedSocket::Close(true); } void Page(std::stringstream* n, unsigned int response, HTTPHeaders* hheaders) @@ -323,16 +333,6 @@ class HttpServerSocket : public BufferedSocket, public Timer, public insp::intru Page(n->str(), response, hheaders); } - void AddToCull() - { - if (waitingcull) - return; - - waitingcull = true; - Close(); - ServerInstance->GlobalCulls.AddItem(this); - } - bool ParseURI(const std::string& uristr, HTTPRequestURI& out) { http_parser_url_init(&url); @@ -439,7 +439,7 @@ class ModuleHttpServer : public Module for (insp::intrusive_list<HttpServerSocket>::const_iterator i = sockets.begin(); i != sockets.end(); ++i) { HttpServerSocket* sock = *i; - sock->AddToCull(); + sock->Close(); } return Module::cull(); } |