enet: Fix a memory leak when peer:send fails (thanks pfirsich!)

This commit is contained in:
Alex Szpakowski
2018-01-06 01:03:41 -04:00
parent f66753fec2
commit 08b3635e4e
+8 -2
View File
@@ -712,8 +712,14 @@ static int peer_send(lua_State *l) {
ENetPacket *packet = read_packet(l, 2, &channel_id);
// printf("sending, channel_id=%d\n", channel_id);
enet_peer_send(peer, channel_id, packet);
return 0;
int ret = enet_peer_send(peer, channel_id, packet);
if (ret < 0) {
enet_packet_destroy(packet);
}
lua_pushinteger(l, ret);
return 1;
}
static const struct luaL_Reg enet_funcs [] = {