Commit 727c7bbe authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

Handle FreeBuffer(nil)

parent d60b0f23
...@@ -20,7 +20,7 @@ type GcBufferPool struct { ...@@ -20,7 +20,7 @@ type GcBufferPool struct {
} }
// NewGcBufferPool is just a fallback to the standard allocation routines. // NewGcBufferPool is just a fallback to the standard allocation routines.
func NewGcBufferPool() *GcBufferPool { func NewGcBufferPool() *GcBufferPool {
return &GcBufferPool{} return &GcBufferPool{}
} }
...@@ -80,7 +80,7 @@ func (me *BufferPoolImpl) getBuffer(pageCount int) []byte { ...@@ -80,7 +80,7 @@ func (me *BufferPoolImpl) getBuffer(pageCount int) []byte {
return result return result
} }
} }
return nil return nil
} }
...@@ -98,7 +98,7 @@ func (me *BufferPoolImpl) AllocBuffer(size uint32) []byte { ...@@ -98,7 +98,7 @@ func (me *BufferPoolImpl) AllocBuffer(size uint32) []byte {
if sz < PAGESIZE { if sz < PAGESIZE {
sz = PAGESIZE sz = PAGESIZE
} }
if sz % PAGESIZE != 0 { if sz % PAGESIZE != 0 {
sz += PAGESIZE sz += PAGESIZE
} }
...@@ -108,7 +108,7 @@ func (me *BufferPoolImpl) AllocBuffer(size uint32) []byte { ...@@ -108,7 +108,7 @@ func (me *BufferPoolImpl) AllocBuffer(size uint32) []byte {
defer me.lock.Unlock() defer me.lock.Unlock()
var b []byte var b []byte
b = me.getBuffer(psz) b = me.getBuffer(psz)
if b == nil { if b == nil {
me.createdBuffers++ me.createdBuffers++
...@@ -134,7 +134,7 @@ func (me *BufferPoolImpl) FreeBuffer(slice []byte) { ...@@ -134,7 +134,7 @@ func (me *BufferPoolImpl) FreeBuffer(slice []byte) {
if slice == nil { if slice == nil {
return return
} }
if cap(slice) % PAGESIZE != 0 { if cap(slice) % PAGESIZE != 0 || cap(slice) == 0 {
return return
} }
psz := cap(slice) / PAGESIZE psz := cap(slice) / PAGESIZE
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment