fix bytepool out of range panic
This commit is contained in:
parent
8f67c1018e
commit
736026d9d3
1 changed files with 5 additions and 2 deletions
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue