From 59ec3dc267c8cb131d08a78e1fa7ed9c83543f9a Mon Sep 17 00:00:00 2001 From: rubidium Date: Wed, 7 Oct 2009 21:11:56 +0000 Subject: (svn r17743) -Fix: (post 0.7) memory leak in server in case handling a packet caused the connection to be closed. Also force-close the connection on invalid packets. --- src/network/network_server.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/network/network_server.cpp b/src/network/network_server.cpp index bea3c558a..ebc23e89d 100644 --- a/src/network/network_server.cpp +++ b/src/network/network_server.cpp @@ -1566,17 +1566,18 @@ bool NetworkServerChangeClientName(ClientID client_id, const char *new_name) void NetworkServer_ReadPackets(NetworkClientSocket *cs) { Packet *p; - NetworkRecvStatus res; - while ((p = cs->Recv_Packet()) != NULL) { + NetworkRecvStatus res = NETWORK_RECV_STATUS_OKAY; + + while (res == NETWORK_RECV_STATUS_OKAY && (p = cs->Recv_Packet()) != NULL) { byte type = p->Recv_uint8(); if (type < PACKET_END && _network_server_packet[type] != NULL && !cs->HasClientQuit()) { res = _network_server_packet[type](cs, p); - - /* Something didn't go as expected */ - if (res != NETWORK_RECV_STATUS_OKAY) return; } else { + cs->CloseConnection(); + res = NETWORK_RECV_STATUS_MALFORMED_PACKET; DEBUG(net, 0, "[server] received invalid packet type %d", type); } + delete p; } } -- cgit v1.2.3-70-g09d2