Skip to content

Commit 41bc1c9

Browse files
committed
internal/mux: bug fix: crash when changing the buffer size
Closes #258
1 parent c03eaf3 commit 41bc1c9

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

internal/mux/mux.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ func (p *playerImpl) setBufferSize(bufferSize int) {
251251

252252
func (p *playerImpl) getTmpBuf() ([]byte, func()) {
253253
// The returned buffer could be accessed regardless of the mutex m (#254).
254-
// In order to oavoid races, use a sync.Pool.
254+
// In order to avoid races, use a sync.Pool.
255255
// On the other hand, the calls of getTmpBuf itself should be protected by the mutex m,
256256
// then accessing p.bufPool doesn't cause races.
257257
if p.bufPool == nil {
@@ -264,6 +264,11 @@ func (p *playerImpl) getTmpBuf() ([]byte, func()) {
264264
}
265265
buf := p.bufPool.Get().(*[]byte)
266266
return *buf, func() {
267+
// p.bufPool could be nil when setBufferSize is called (#258).
268+
// buf doesn't have to (or cannot) be put back to the pool, as the size of the buffer could be changed.
269+
if p.bufPool == nil {
270+
return
271+
}
267272
p.bufPool.Put(buf)
268273
}
269274
}

0 commit comments

Comments
 (0)