From: Matt Joiner Date: Wed, 20 Mar 2019 00:01:56 +0000 (+1100) Subject: Fix race condition in Torrent.SetDisplayName X-Git-Tag: v1.1.1^0 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=499b2d8725f44506a0172a0952e6313769833efd;p=btrtrc.git Fix race condition in Torrent.SetDisplayName --- diff --git a/t.go b/t.go index c76d9273..cd8bc10c 100644 --- a/t.go +++ b/t.go @@ -107,9 +107,12 @@ func (t *Torrent) Seeding() bool { // Clobbers the torrent display name. The display name is used as the torrent // name if the metainfo is not available. func (t *Torrent) SetDisplayName(dn string) { - t.cl.lock() - defer t.cl.unlock() - t.setDisplayName(dn) + t.nameMu.Lock() + defer t.nameMu.Unlock() + if t.haveInfo() { + return + } + t.displayName = dn } // The current working name for the torrent. Either the name in the info dict, diff --git a/torrent.go b/torrent.go index 6f609206..c9ccaa9f 100644 --- a/torrent.go +++ b/torrent.go @@ -196,13 +196,6 @@ func (t *Torrent) setChunkSize(size pp.Integer) { } } -func (t *Torrent) setDisplayName(dn string) { - if t.haveInfo() { - return - } - t.displayName = dn -} - func (t *Torrent) pieceComplete(piece pieceIndex) bool { return t.completedPieces.Get(bitmap.BitIndex(piece)) }