Mercurial > hg > openttd
changeset 13236:0d23b42f0504 draft
(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.
author | rubidium <rubidium@openttd.org> |
---|---|
date | Wed, 07 Oct 2009 21:11:56 +0000 |
parents | 43c90fdf90fc |
children | 30bea6aca458 |
files | src/network/network_server.cpp |
diffstat | 1 files changed, 6 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/src/network/network_server.cpp +++ b/src/network/network_server.cpp @@ -1566,17 +1566,18 @@ 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; } }