Skip to content

Commit

Permalink
Fix memory/thread leak in the HttpServerConnection class
Browse files Browse the repository at this point in the history
fixes #10655
  • Loading branch information
gunnarbeutner committed Feb 23, 2016
1 parent b6a799d commit 9a0107d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
28 changes: 22 additions & 6 deletions lib/base/tlsstream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -208,7 +208,7 @@ void TlsStream::OnEvent(int revents)

Close();

break;
return;
default:
m_ErrorCode = ERR_peek_error();
m_ErrorOccurred = true;
Expand All @@ -224,7 +224,7 @@ void TlsStream::OnEvent(int revents)

Close();

break;
return;
}
}

Expand All @@ -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();
}
}

Expand Down Expand Up @@ -311,17 +313,31 @@ void TlsStream::Write(const void *buffer, size_t count)
void TlsStream::Shutdown(void)
{
m_Shutdown = true;
ChangeEvents(POLLOUT);
}

/**
* Closes the stream.
*/
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();

Expand Down
3 changes: 1 addition & 2 deletions lib/remote/httpserverconnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 9a0107d

Please sign in to comment.