mirror of
https://github.com/bluenviron/mediamtx
synced 2024-12-13 18:24:58 +00:00
fix memory leak caused by time.Timer
This commit is contained in:
parent
0495c1ed4b
commit
08823ddc92
@ -46,14 +46,8 @@ func (e *ExternalCmd) run() {
|
||||
defer close(e.done)
|
||||
|
||||
for {
|
||||
if !e.runInner() {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (e *ExternalCmd) runInner() bool {
|
||||
ok := e.runInnerInner()
|
||||
ok := func() bool {
|
||||
ok := e.runInner()
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
@ -72,9 +66,14 @@ func (e *ExternalCmd) runInner() bool {
|
||||
case <-e.terminate:
|
||||
return false
|
||||
}
|
||||
}()
|
||||
if !ok {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (e *ExternalCmd) runInnerInner() bool {
|
||||
func (e *ExternalCmd) runInner() bool {
|
||||
var cmd *exec.Cmd
|
||||
if runtime.GOOS == "windows" {
|
||||
// on Windows the shell is not used and command is started directly
|
||||
|
@ -123,20 +123,25 @@ outer:
|
||||
func (s *Source) runInner() {
|
||||
defer close(s.innerDone)
|
||||
|
||||
outer:
|
||||
for {
|
||||
ok := func() bool {
|
||||
ok := s.runInnerInner()
|
||||
if !ok {
|
||||
break outer
|
||||
return false
|
||||
}
|
||||
|
||||
t := time.NewTimer(retryInterval)
|
||||
defer t.Stop()
|
||||
|
||||
select {
|
||||
case <-s.innerTerminate:
|
||||
break outer
|
||||
case <-t.C:
|
||||
return true
|
||||
case <-s.innerTerminate:
|
||||
return false
|
||||
}
|
||||
}()
|
||||
if !ok {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -209,6 +214,7 @@ func (s *Source) runInnerInner() bool {
|
||||
}()
|
||||
|
||||
timer := time.NewTimer(5 * time.Second)
|
||||
defer timer.Stop()
|
||||
|
||||
select {
|
||||
case <-confDone:
|
||||
|
@ -127,20 +127,25 @@ outer:
|
||||
func (s *Source) runInner() {
|
||||
defer close(s.innerDone)
|
||||
|
||||
outer:
|
||||
for {
|
||||
ok := func() bool {
|
||||
ok := s.runInnerInner()
|
||||
if !ok {
|
||||
break outer
|
||||
return false
|
||||
}
|
||||
|
||||
t := time.NewTimer(retryInterval)
|
||||
defer t.Stop()
|
||||
|
||||
select {
|
||||
case <-s.innerTerminate:
|
||||
break outer
|
||||
case <-t.C:
|
||||
return true
|
||||
case <-s.innerTerminate:
|
||||
return false
|
||||
}
|
||||
}()
|
||||
if !ok {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user