From dc7428db542600734f83f460aa4f1ae77c0b9dc4 Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Mon, 31 Oct 2016 19:05:33 +1100 Subject: [PATCH] Reader.Close: Prefer to lock Client in public method --- reader.go | 2 ++ t.go | 2 -- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/reader.go b/reader.go index b3b6fd9b..0336a2fd 100644 --- a/reader.go +++ b/reader.go @@ -208,6 +208,8 @@ func (r *Reader) readOnceAt(b []byte, pos int64, ctxErr *error) (n int, err erro } func (r *Reader) Close() error { + r.t.cl.mu.Lock() + defer r.t.cl.mu.Unlock() r.t.deleteReader(r) r.t = nil return nil diff --git a/t.go b/t.go index b17226be..8454d02b 100644 --- a/t.go +++ b/t.go @@ -136,8 +136,6 @@ func (t *Torrent) addReader(r *Reader) { } func (t *Torrent) deleteReader(r *Reader) { - t.cl.mu.Lock() - defer t.cl.mu.Unlock() delete(t.readers, r) t.readersChanged() }