Tighten up some potential leaks

Based on some observations of lingering goroutines in unit tests.
This commit is contained in:
Matt Joiner 2015-08-04 01:15:09 +10:00
parent 54339a30e3
commit f69c51bea3
1 changed files with 14 additions and 1 deletions

View File

@ -551,14 +551,22 @@ func (cl *Client) stopped() bool {
func (me *Client) Close() {
me.mu.Lock()
defer me.mu.Unlock()
select {
case <-me.quit:
return
default:
}
close(me.quit)
if me.dHT != nil {
me.dHT.Close()
}
for _, l := range me.listeners {
l.Close()
}
me.event.Broadcast()
for _, t := range me.torrents {
t.close()
}
me.event.Broadcast()
}
var ipv6BlockRange = iplist.Range{Description: "non-IPv4 address"}
@ -586,6 +594,11 @@ func (cl *Client) waitAccept() {
return
}
}
select {
case <-cl.quit:
return
default:
}
cl.event.Wait()
}
}