From 4a5c4f6089b344c4e385a1f1e4d26545f46f4984 Mon Sep 17 00:00:00 2001 From: rubidium Date: Sun, 8 Mar 2009 16:14:14 +0000 Subject: [PATCH] (svn r15644) -Fix [FS#2710]: closing a network connection twice in the case that sending packets starts failing while disconnecting --- src/network/network.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/network/network.cpp b/src/network/network.cpp index 542d4f52cd..f3b036592c 100644 --- a/src/network/network.cpp +++ b/src/network/network.cpp @@ -422,7 +422,14 @@ static NetworkClientSocket *NetworkAllocClient(SOCKET s) // Close a connection void NetworkCloseClient(NetworkClientSocket *cs) { - assert(cs->sock != INVALID_SOCKET); + /* + * Sending a message just before leaving the game calls cs->Send_Packets. + * This might invoke this function, which means that when we close the + * connection after cs->Send_Packets we will close an already closed + * connection. This handles that case gracefully without having to make + * that code any more complex or more aware of the validity of the socket. + */ + if (cs->sock == INVALID_SOCKET) return; DEBUG(net, 1, "Closed client connection %d", cs->client_id);