From 7eaef48f9efe2128ceb9e608f1c9c3d1bc6b886f Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Sun, 14 Sep 2014 04:07:05 +1000 Subject: [PATCH] Fix crash when piece hash completes for dropped torrent --- client.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) 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) { -- 2.48.1