From 7010cec326b5d71691931d4ee170f121fe9dc598 Mon Sep 17 00:00:00 2001 From: onthegit Date: Mon, 22 Feb 2021 23:44:19 +0100 Subject: [PATCH] Fix Memory leak --- container/flv/muxer.go | 5 +++++ protocol/rtmp/stream.go | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/container/flv/muxer.go b/container/flv/muxer.go index fdcc07a8..932b261a 100755 --- a/container/flv/muxer.go +++ b/container/flv/muxer.go @@ -56,6 +56,7 @@ type FLVWriter struct { buf []byte closed chan struct{} ctx *os.File + closedWriter bool } func NewFLVWriter(app, title, url string, ctx *os.File) *FLVWriter { @@ -131,6 +132,10 @@ func (writer *FLVWriter) Wait() { } func (writer *FLVWriter) Close(error) { + if writer.closedWriter { + return + } + writer.closedWriter = true writer.ctx.Close() close(writer.closed) } diff --git a/protocol/rtmp/stream.go b/protocol/rtmp/stream.go index 9ce18416..f793bb98 100755 --- a/protocol/rtmp/stream.go +++ b/protocol/rtmp/stream.go @@ -379,7 +379,7 @@ func (s *Stream) CheckAlive() (n int) { v := val.(*PackWriterCloser) if v.w != nil { //Alive from RWBaser, check last frame now - timestamp, if > timeout then Remove it - if !v.w.Alive() && s.isStart { + if !v.w.Alive() { log.Infof("write timeout remove") s.ws.Delete(key) v.w.Close(fmt.Errorf("write timeout"))