]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Fix panic when setting info bytes after Torrent closed
authorMatt Joiner <anacrolix@gmail.com>
Fri, 18 Jul 2025 13:08:33 +0000 (23:08 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Fri, 18 Jul 2025 13:08:33 +0000 (23:08 +1000)
torrent.go

index 104733f9b824635511a96741b661210e21556645..c4ba4ecb66bcf75eb041110d2b378d31098601ee 100644 (file)
@@ -1827,6 +1827,10 @@ func (t *Torrent) bytesCompleted() int64 {
 func (t *Torrent) SetInfoBytes(b []byte) (err error) {
        t.cl.lock()
        defer t.cl.unlock()
+       err = t.getClosedErr()
+       if err != nil {
+               return
+       }
        return t.setInfoBytesLocked(b)
 }
 
@@ -3521,3 +3525,10 @@ func (t *Torrent) wantReceiveChunk(reqIndex RequestIndex) bool {
        }
        return true
 }
+
+func (t *Torrent) getClosedErr() error {
+       if t.closed.IsSet() {
+               return errTorrentClosed
+       }
+       return nil
+}