From ea471ff2ce48e46b4aa4e273904ce295a91723d9 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Thu, 23 Jun 2016 22:41:46 +0300 Subject: [PATCH] Do not return buffers with too big capacity to the pool --- pool.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pool.go b/pool.go index 6519ec8..e15e1ee 100644 --- a/pool.go +++ b/pool.go @@ -38,8 +38,7 @@ func (p *byteBufferPool) Acquire() *ByteBuffer { } func (p *byteBufferPool) Release(b *ByteBuffer) { - bSize := len(b.B) - idx := bitSize(bSize-1) - minBitSize + idx := bitSize(len(b.B)-1) - minBitSize if idx < 0 { idx = 0 } else if idx >= steps { @@ -51,7 +50,7 @@ func (p *byteBufferPool) Release(b *ByteBuffer) { } maxSize := int(atomic.LoadUint64(&p.maxSize)) - if maxSize > 0 && bSize <= maxSize { + if maxSize > 0 && cap(b.B) <= maxSize { b.B = b.B[:0] p.pool.Put(b) }