From f661dcfb5943e0e7c26694476bd6c30b3badae4a Mon Sep 17 00:00:00 2001 From: Soheil Hassas Yeganeh Date: Sun, 25 Sep 2016 11:40:41 -0400 Subject: [PATCH] Reset the sniffing buffer when not needed The sniffing buffer will live as long as the connection is open, and we should reset it as soon as the application has read all the sniffed data. --- buffer.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/buffer.go b/buffer.go index d05b199..f8cf30a 100644 --- a/buffer.go +++ b/buffer.go @@ -42,6 +42,10 @@ func (s *bufferedReader) Read(p []byte) (int, error) { bn := copy(p, s.buffer.Bytes()[s.bufferRead:s.bufferSize]) s.bufferRead += bn return bn, s.lastErr + } else if !s.sniffing && s.buffer.Cap() != 0 { + // We don't need the buffer anymore. + // Reset it to release the internal slice. + s.buffer = bytes.Buffer{} } // If there is nothing more to return in the sniffed buffer, read from the