Commit 249e144f authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

Don't crash on FreeBuffer() with zero-length slice.

parent db03ba71
...@@ -106,7 +106,7 @@ func (me *BufferPool) FreeBuffer(slice []byte) { ...@@ -106,7 +106,7 @@ func (me *BufferPool) FreeBuffer(slice []byte) {
if cap(slice) < PAGESIZE { if cap(slice) < PAGESIZE {
return return
} }
slice = slice[:cap(slice)]
key := uintptr(unsafe.Pointer(&slice[0])) key := uintptr(unsafe.Pointer(&slice[0]))
exp, ok := me.outstandingBuffers[key] exp, ok := me.outstandingBuffers[key]
if ok { if ok {
......
...@@ -39,3 +39,9 @@ func TestBufferPool(t *testing.T) { ...@@ -39,3 +39,9 @@ func TestBufferPool(t *testing.T) {
} }
} }
func TestFreeBufferEmpty(t *testing.T) {
bp := NewBufferPool()
c := make([]byte, 0, 2*PAGESIZE)
bp.FreeBuffer(c)
}
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