Changeset - r13226:9c8b9a432c01
[Not reviewed]
master
0 1 0
rubidium - 15 years ago 2009-10-07 21:11:56
rubidium@openttd.org
(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.
1 file changed with 6 insertions and 5 deletions:
0 comments (0 inline, 0 general)
src/network/network_server.cpp
Show inline comments
 
@@ -1566,17 +1566,18 @@ bool NetworkServerChangeClientName(Clien
 
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;
 
	}
 
}
0 comments (0 inline, 0 general)