From 9a0107d360e335a57b1535231bf9591980f7e60f Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Wed, 3 Feb 2016 09:54:31 +0100 Subject: [PATCH] Fix memory/thread leak in the HttpServerConnection class fixes #10655 --- lib/base/tlsstream.cpp | 28 ++++++++++++++++++++++------ lib/remote/httpserverconnection.cpp | 3 +-- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/lib/base/tlsstream.cpp b/lib/base/tlsstream.cpp index be1977e5b..a431199f8 100644 --- a/lib/base/tlsstream.cpp +++ b/lib/base/tlsstream.cpp @@ -189,7 +189,7 @@ void TlsStream::OnEvent(int revents) VERIFY(!"Invalid TlsAction"); } - if (rc < 0) { + if (rc <= 0) { int err = SSL_get_error(m_SSL.get(), rc); switch (err) { @@ -208,7 +208,7 @@ void TlsStream::OnEvent(int revents) Close(); - break; + return; default: m_ErrorCode = ERR_peek_error(); m_ErrorOccurred = true; @@ -224,7 +224,7 @@ void TlsStream::OnEvent(int revents) Close(); - break; + return; } } @@ -242,9 +242,11 @@ void TlsStream::OnEvent(int revents) while (m_RecvQ->IsDataAvailable() && IsHandlingEvents()) SignalDataAvailable(); + } - if (m_Shutdown && !m_SendQ->IsDataAvailable()) - Close(); + if (m_Shutdown && !m_SendQ->IsDataAvailable()) { + lock.unlock(); + Close(); } } @@ -311,6 +313,7 @@ void TlsStream::Write(const void *buffer, size_t count) void TlsStream::Shutdown(void) { m_Shutdown = true; + ChangeEvents(POLLOUT); } /** @@ -318,10 +321,23 @@ void TlsStream::Shutdown(void) */ void TlsStream::Close(void) { +<<<<<<< HEAD if (!m_Eof) { m_Eof = true; +======= + CloseInternal(false); +} + +void TlsStream::CloseInternal(bool inDestructor) +{ + if (m_Eof) + return; + + m_Eof = true; + + if (!inDestructor) +>>>>>>> 2dc385e... Fix memory/thread leak in the HttpServerConnection class SignalDataAvailable(); - } Stream::Close(); diff --git a/lib/remote/httpserverconnection.cpp b/lib/remote/httpserverconnection.cpp index d857ed4bf..4125a75ab 100644 --- a/lib/remote/httpserverconnection.cpp +++ b/lib/remote/httpserverconnection.cpp @@ -78,8 +78,7 @@ void HttpServerConnection::Disconnect(void) ApiListener::Ptr listener = ApiListener::GetInstance(); listener->RemoveHttpClient(this); - if (!m_Stream->IsEof()) - m_Stream->Shutdown(); + m_Stream->Shutdown(); } bool HttpServerConnection::ProcessMessage(void)