mirror of
https://github.com/sot-tech/mochi.git
synced 2026-05-17 13:24:50 -07:00
fix bytepool out of range panic
This commit is contained in:
committed by
Jimmy Zelinskie
parent
8f67c1018e
commit
736026d9d3
@@ -27,9 +27,12 @@ func (bp *BytePool) Get() []byte {
|
||||
|
||||
// Put returns a byte slice to the pool.
|
||||
func (bp *BytePool) Put(b []byte) {
|
||||
b = b[:cap(b)]
|
||||
// Zero out the bytes.
|
||||
for i := 0; i < cap(b); i++ {
|
||||
b[i] = 0x0
|
||||
// Apparently this specific expression is optimized by the compiler, see
|
||||
// github.com/golang/go/issues/5373.
|
||||
for i := range b {
|
||||
b[i] = 0
|
||||
}
|
||||
bp.Pool.Put(b)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user