From: Matt Joiner Date: Sat, 13 Sep 2014 18:07:05 +0000 (+1000) Subject: Fix crash when piece hash completes for dropped torrent X-Git-Tag: v1.0.0~1555 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=7eaef48f9efe2128ceb9e608f1c9c3d1bc6b886f;p=btrtrc.git Fix crash when piece hash completes for dropped torrent --- diff --git a/client.go b/client.go index 61556967..115a9904 100644 --- 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) {