lua-enet icon indicating copy to clipboard operation
lua-enet copied to clipboard

Fix memory leak in peer_send if sending to non-"connected" peer

Open pfirsich opened this issue 8 years ago • 1 comments

If the peer being sent to is not in the "connected" state, enet_peer_send will return -1 and the packet created by read_packet will not be freed.

I stumbled into this bug while I (foolishly) wrote this loop:

for peerIndex = 1, host:peer_count() do
    local peer = host:get_peer(peerIndex)
    if peer ~= event.peer then
        peer:send(event.data, channel, flag)
    end
end

In that way I find the documentation on host:get_peer a little bit confusing: "Returns the connected peer at the specified index", because get_peer may very well return non-"connected" peers. Should the documentation be adjusted as well in that regard?

pfirsich avatar Dec 19 '17 09:12 pfirsich

Looking at this a long time after, I notice I did some other dumb stuff in my fork by accident, because I have forgotten this PR. Obviously it should only be this commit: https://github.com/leafo/lua-enet/pull/19/commits/67f30730efd882d013ed4786e3f9970a4f66b06c I'm not interested in cleaning that up, but noticed it just now.

pfirsich avatar Aug 10 '20 15:08 pfirsich