prevent memory leaks in slice buffer

Remove reference to packets from packet ordering slices to prevent
small memory leak. The leak is bounded and temporary, but this is a good
practice.
This commit is contained in:
John Eikenberry 2018-11-20 16:02:25 -08:00
parent 08de04f133
commit a741a7f1d5
1 changed files with 2 additions and 0 deletions

View File

@ -176,8 +176,10 @@ func (s *packetManager) maybeSendPackets() {
s.sender.sendPacket(out.(encoding.BinaryMarshaler))
// pop off heads
copy(s.incoming, s.incoming[1:]) // shift left
s.incoming[len(s.incoming)-1] = nil // clear last
s.incoming = s.incoming[:len(s.incoming)-1] // remove last
copy(s.outgoing, s.outgoing[1:]) // shift left
s.outgoing[len(s.outgoing)-1] = nil // clear last
s.outgoing = s.outgoing[:len(s.outgoing)-1] // remove last
} else {
break