]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Improve some lock handling under panics
authorMatt Joiner <anacrolix@gmail.com>
Sun, 9 May 2021 07:31:45 +0000 (17:31 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Fri, 14 May 2021 05:36:53 +0000 (15:36 +1000)
t.go
torrent.go

diff --git a/t.go b/t.go
index a0b5cb59a55070eb4fdbae394640e2b318ceed3e..a3be2d266c3cff9a2922746edfa3a3765e43917b 100644 (file)
--- 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
index 52fff16a15ecff935d43b853898665a86503d6e9..32b7e5fda1a74e67b0fa24c8f304d6e9541e7aad 100644 (file)
@@ -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()