From a6e16b4f740211f56faa1368d6dd118372d1e54c Mon Sep 17 00:00:00 2001 From: Qian Wang Date: Sat, 19 Jan 2019 19:30:00 +0000 Subject: [PATCH] Fix memory leak --- internal/multiplex/frameSorter.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/internal/multiplex/frameSorter.go b/internal/multiplex/frameSorter.go index de5902f..cf709fa 100644 --- a/internal/multiplex/frameSorter.go +++ b/internal/multiplex/frameSorter.go @@ -74,6 +74,11 @@ func (s *Stream) recvNewFrame() { // when there's no ooo packages in heap and we receive the next package in order if len(s.sh) == 0 && f.Seq == s.nextRecvSeq { s.pushFrame(f) + if f.Closing == 1 { + // empty data indicates closing signal + s.sortedBufCh <- []byte{} + return + } continue } @@ -104,6 +109,11 @@ func (s *Stream) recvNewFrame() { // Keep popping from the heap until empty or to the point that the wanted seq was not received for len(s.sh) > 0 && s.sh[0].frame.Seq == s.nextRecvSeq { frame := heap.Pop(&s.sh).(*frameNode).frame + if frame.Closing == 1 { + // empty data indicates closing signal + s.sortedBufCh <- []byte{} + return + } s.pushFrame(frame) } } @@ -111,11 +121,6 @@ func (s *Stream) recvNewFrame() { } func (s *Stream) pushFrame(f *Frame) { - if f.Closing == 1 { - // empty data indicates closing signal - s.sortedBufCh <- []byte{} - return - } s.sortedBufCh <- f.Payload s.nextRecvSeq += 1 if s.nextRecvSeq == 0 { // getting wrapped