From 4ab20f60b6d9fdf81174e210e99964df63be1d51 Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Sun, 9 May 2021 17:31:45 +1000 Subject: [PATCH] Improve some lock handling under panics --- t.go | 2 +- torrent.go | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) 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()