8000 prevent memory leaks in slice buffer · etherscan-io/sftp@a741a7f · GitHub
[go: up one dir, main page]

Skip to content {"props":{"docsUrl":"https://docs.github.com/get-started/accessibility/keyboard-shortcuts"}}

Commit a741a7f

Browse files
committed
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.
1 parent 08de04f commit a741a7f

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

packet-manager.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,10 @@ func (s *packetManager) maybeSendPackets() {
176176
s.sender.sendPacket(out.(encoding.BinaryMarshaler))
177177
// pop off heads
178178
copy(s.incoming, s.incoming[1:]) // shift left
179+
s.incoming[len(s.incoming)-1] = nil // clear last
179180
s.incoming = s.incoming[:len(s.incoming)-1] // remove last
180181
copy(s.outgoing, s.outgoing[1:]) // shift left
182+
s.outgoing[len(s.outgoing)-1] = nil // clear last
181183
s.outgoing = s.outgoing[:len(s.outgoing)-1] // remove last
182184
} else {
183185
break

0 commit comments

Comments
 (0)
0