NETWORK: plug memory leak if enet_peer_send failed

Martin Gerhardy 2019-11-16 20:54:16 +01:00
parent 1268293a26
commit 95629fc312
3 changed files with 7 additions and 2 deletions

View File

@ -196,7 +196,7 @@ enet_peer_send (ENetPeer * peer, enet_uint8 channelID, ENetPacket * packet)
command.sendUnsequenced.dataLength = ENET_HOST_TO_NET_16 (packet -> dataLength);
}
else
if (packet -> flags & ENET_PACKET_FLAG_RELIABLE || channel -> outgoingUnreliableSequenceNumber >= 0xFFFF)
if ((packet -> flags & ENET_PACKET_FLAG_RELIABLE) || channel -> outgoingUnreliableSequenceNumber >= 0xFFFF)
{
command.header.command = ENET_PROTOCOL_COMMAND_SEND_RELIABLE | ENET_PROTOCOL_COMMAND_FLAG_ACKNOWLEDGE;
command.sendReliable.dataLength = ENET_HOST_TO_NET_16 (packet -> dataLength);

View File

@ -24,6 +24,7 @@ public:
inline bool sendMessage(ENetPacket* packet, int channel = 0) {
if (_peer == nullptr) {
enet_packet_destroy(packet);
return false;
}
if (packet == nullptr) {

View File

@ -54,7 +54,11 @@ public:
};
inline bool Network::sendMessage(ENetPeer* peer, ENetPacket* packet, int channel) {
return enet_peer_send(peer, channel, packet) == 0;
if (enet_peer_send(peer, channel, packet) == 0) {
return true;
}
enet_packet_destroy(packet);
return false;
}
inline const ProtocolHandlerRegistryPtr& Network::registry() {