Browse Source

Merge pull request #160 from onthegit/master

Fix Memory leak
pull/171/head
Matthew 4 years ago committed by GitHub
parent
commit
3486323747
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      container/flv/muxer.go
  2. 2
      protocol/rtmp/stream.go

5
container/flv/muxer.go

@ -56,6 +56,7 @@ type FLVWriter struct {
buf []byte buf []byte
closed chan struct{} closed chan struct{}
ctx *os.File ctx *os.File
closedWriter bool
} }
func NewFLVWriter(app, title, url string, ctx *os.File) *FLVWriter { func NewFLVWriter(app, title, url string, ctx *os.File) *FLVWriter {
@ -131,6 +132,10 @@ func (writer *FLVWriter) Wait() {
} }
func (writer *FLVWriter) Close(error) { func (writer *FLVWriter) Close(error) {
if writer.closedWriter {
return
}
writer.closedWriter = true
writer.ctx.Close() writer.ctx.Close()
close(writer.closed) close(writer.closed)
} }

2
protocol/rtmp/stream.go

@ -379,7 +379,7 @@ func (s *Stream) CheckAlive() (n int) {
v := val.(*PackWriterCloser) v := val.(*PackWriterCloser)
if v.w != nil { if v.w != nil {
//Alive from RWBaser, check last frame now - timestamp, if > timeout then Remove it //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") log.Infof("write timeout remove")
s.ws.Delete(key) s.ws.Delete(key)
v.w.Close(fmt.Errorf("write timeout")) v.w.Close(fmt.Errorf("write timeout"))

Loading…
Cancel
Save