From: Matt Joiner Date: Sun, 9 May 2021 07:31:45 +0000 (+1000) Subject: Improve some lock handling under panics X-Git-Tag: v1.28.0~17 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=4ab20f60b6d9fdf81174e210e99964df63be1d51;p=btrtrc.git Improve some lock handling under panics --- diff --git a/t.go b/t.go index a0b5cb59..a3be2d26 100644 --- a/t.go +++ b/t.go @@ -85,8 +85,8 @@ func (t *Torrent) PieceBytesMissing(piece int) int64 { // or connected peers. func (t *Torrent) Drop() { t.cl.lock() + defer t.cl.unlock() t.cl.dropTorrent(t.infoHash) - t.cl.unlock() } // Number of bytes of the entire torrent we have completed. This is the sum of diff --git a/torrent.go b/torrent.go index 52fff16a..32b7e5fd 100644 --- a/torrent.go +++ b/torrent.go @@ -741,9 +741,11 @@ func (t *Torrent) close() (err error) { t.closed.Set() t.tickleReaders() if t.storage != nil { - t.storageLock.Lock() - t.storage.Close() - t.storageLock.Unlock() + func() { + t.storageLock.Lock() + defer t.storageLock.Unlock() + t.storage.Close() + }() } t.iterPeers(func(p *Peer) { p.close()