Skip to content

Commit

Permalink
fix buffer leak
Browse files Browse the repository at this point in the history
  • Loading branch information
mregen committed Apr 10, 2023
1 parent a4b31d6 commit 59109ff
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions Stack/Opc.Ua.Core/Stack/Tcp/TcpMessageSocket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,12 @@ private void OnReadComplete(object sender, SocketAsyncEventArgs e)
e?.Dispose();
}

if (m_readState == ReadState.NotConnected &&
ServiceResult.IsGood(error))
{
error = ServiceResult.Create(StatusCodes.BadConnectionClosed, "Remote side closed connection.");
}

if (ServiceResult.IsBad(error))
{
if (m_receiveBuffer != null)
Expand Down Expand Up @@ -673,22 +679,11 @@ private void ReadNextBlock()
// check if already closed.
lock (m_socketLock)
{
if (m_socket == null)
{
if (m_receiveBuffer != null)
{
m_bufferManager.ReturnBuffer(m_receiveBuffer, "ReadNextBlock");
m_receiveBuffer = null;
}
m_readState = ReadState.NotConnected;
return;
}

socket = m_socket;

// avoid stale ServiceException when socket is disconnected
if (!socket.Connected)
if (socket == null || !socket.Connected)
{
// buffer is returned in calling code
m_readState = ReadState.NotConnected;
return;
}
Expand Down

0 comments on commit 59109ff

Please sign in to comment.