]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Fix crash when piece hash completes for dropped torrent
authorMatt Joiner <anacrolix@gmail.com>
Sat, 13 Sep 2014 18:07:05 +0000 (04:07 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Sat, 13 Sep 2014 18:07:05 +0000 (04:07 +1000)
client.go

index 61556967ea9e76c82c79af12861832bbd9d68447..115a9904bb890b59a5cc95c2a119c00ada03b2b1 100644 (file)
--- a/client.go
+++ b/client.go
@@ -1502,12 +1502,12 @@ func (me *Client) pieceHashed(t *torrent, piece pp.Integer, correct bool) {
 
 func (cl *Client) verifyPiece(t *torrent, index pp.Integer) {
        cl.mu.Lock()
+       defer cl.mu.Unlock()
        p := t.Pieces[index]
        for p.Hashing {
                cl.event.Wait()
        }
        if t.isClosed() {
-               cl.mu.Unlock()
                return
        }
        p.Hashing = true
@@ -1515,9 +1515,13 @@ func (cl *Client) verifyPiece(t *torrent, index pp.Integer) {
        cl.mu.Unlock()
        sum := t.HashPiece(index)
        cl.mu.Lock()
+       select {
+       case <-t.closing:
+               return
+       default:
+       }
        p.Hashing = false
        cl.pieceHashed(t, index, sum == p.Hash)
-       cl.mu.Unlock()
 }
 
 func (me *Client) Torrents() (ret []*torrent) {