]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Fix race condition in Torrent.SetDisplayName v1.1.1
authorMatt Joiner <anacrolix@gmail.com>
Wed, 20 Mar 2019 00:01:56 +0000 (11:01 +1100)
committerMatt Joiner <anacrolix@gmail.com>
Wed, 20 Mar 2019 00:01:56 +0000 (11:01 +1100)
t.go
torrent.go

diff --git a/t.go b/t.go
index c76d92737a4a7310ed768717bfcf117207534634..cd8bc10cd88b9e9be2bcad880756005fdf515af4 100644 (file)
--- 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,
index 6f609206d3ebaf2dbd7f82a83a33b6e7d10caa67..c9ccaa9f042531d300f3aacf2234905caa134a83 100644 (file)
@@ -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))
 }