From b474b9fb5d95f3c511ce0f01f4a6c3e205f13629 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Sun, 22 Feb 2015 19:05:43 +0100 Subject: Fixed race condition for TCP link deleting. This could have caused crashes when a client disconnected from the server. --- src/ClientHandle.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index c774a92c2..2e0e86653 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -1892,9 +1892,13 @@ void cClientHandle::Tick(float a_Dt) cCSLock Lock(m_CSOutgoingData); std::swap(OutgoingData, m_OutgoingData); } - if ((m_Link != nullptr) && !OutgoingData.empty()) + if (!OutgoingData.empty()) { - m_Link->Send(OutgoingData.data(), OutgoingData.size()); + cTCPLinkPtr Link(m_Link); // Grab a copy of the link in a multithread-safe way + if ((Link != nullptr)) + { + Link->Send(OutgoingData.data(), OutgoingData.size()); + } } m_TicksSinceLastPacket += 1; -- cgit v1.2.3