diff options
author | rubidium <rubidium@openttd.org> | 2007-06-09 04:01:40 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2007-06-09 04:01:40 +0000 |
commit | 02146b13c84215dde6dd1eadf58260c2b34100c1 (patch) | |
tree | 6215c3ceff1030a62f5faa7df75307c3d9ec2dff | |
parent | 9a4a911bdecd3287cc2e28dad93ce56c13a87ec4 (diff) | |
download | openttd-02146b13c84215dde6dd1eadf58260c2b34100c1.tar.xz |
(svn r10075) -Fix [FS#844]: small memory leak on some early returns.
-rw-r--r-- | src/network/network_server.cpp | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/src/network/network_server.cpp b/src/network/network_server.cpp index b2d6c73c1..736fe64a1 100644 --- a/src/network/network_server.cpp +++ b/src/network/network_server.cpp @@ -832,8 +832,6 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_COMMAND) const NetworkClientInfo *ci; byte callback; - CommandPacket *cp = MallocT<CommandPacket>(1); - // The client was never joined.. so this is impossible, right? // Ignore the packet, give the client a warning, and close his connection if (cs->status < STATUS_DONE_MAP || cs->has_quit) { @@ -841,6 +839,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_COMMAND) return; } + CommandPacket *cp = MallocT<CommandPacket>(1); cp->player = (Owner)p->Recv_uint8(); cp->cmd = p->Recv_uint32(); cp->p1 = p->Recv_uint32(); @@ -850,7 +849,10 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_COMMAND) callback = p->Recv_uint8(); - if (cs->has_quit) return; + if (cs->has_quit) { + free(cp); + return; + } ci = DEREF_CLIENT_INFO(cs); @@ -858,11 +860,13 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_COMMAND) if (!IsValidCommand(cp->cmd)) { IConsolePrintF(_icolour_err, "WARNING: invalid command from client %d (IP: %s).", ci->client_index, GetPlayerIP(ci)); SEND_COMMAND(PACKET_SERVER_ERROR)(cs, NETWORK_ERROR_NOT_EXPECTED); + free(cp); return; } if (!CheckCommandFlags(cp, ci)) { SEND_COMMAND(PACKET_SERVER_ERROR)(cs, NETWORK_ERROR_KICKED); + free(cp); return; } @@ -874,6 +878,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_COMMAND) IConsolePrintF(_icolour_err, "WARNING: player %d (IP: %s) tried to execute a command as player %d, kicking...", ci->client_playas + 1, GetPlayerIP(ci), cp->player + 1); SEND_COMMAND(PACKET_SERVER_ERROR)(cs, NETWORK_ERROR_PLAYER_MISMATCH); + free(cp); return; } @@ -885,6 +890,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_COMMAND) if (cp->cmd == CMD_PLAYER_CTRL) { if (cp->p1 != 0) { SEND_COMMAND(PACKET_SERVER_ERROR)(cs, NETWORK_ERROR_CHEATER); + free(cp); return; } |