diff options
author | rubidium <rubidium@openttd.org> | 2009-10-07 21:11:56 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2009-10-07 21:11:56 +0000 |
commit | 59ec3dc267c8cb131d08a78e1fa7ed9c83543f9a (patch) | |
tree | 489c217dd9a920a618931fa6da834c89063c272d | |
parent | df75db67ebe271e9de92cc65872ff65b46e4ad4a (diff) | |
download | openttd-59ec3dc267c8cb131d08a78e1fa7ed9c83543f9a.tar.xz |
(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.
-rw-r--r-- | src/network/network_server.cpp | 11 |
1 files 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; } } |