From f45fa6e918639a0495b23ab7ac77cda61fab2572 Mon Sep 17 00:00:00 2001 From: v2ray Date: Sat, 16 Jul 2016 13:22:08 +0200 Subject: [PATCH] allow buffer on local stack --- common/alloc/buffer.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/common/alloc/buffer.go b/common/alloc/buffer.go index ecdb53a5a..896e9d36c 100644 --- a/common/alloc/buffer.go +++ b/common/alloc/buffer.go @@ -35,7 +35,9 @@ func (b *Buffer) Release() { if b == nil || b.head == nil { return } - b.pool.Free(b) + if b.pool != nil { + b.pool.Free(b) + } b.head = nil b.Value = nil b.pool = nil @@ -216,3 +218,7 @@ func NewBufferWithSize(size int) *Buffer { return NewLargeBuffer() } + +func NewLocalBuffer(size int) *Buffer { + return CreateBuffer(make([]byte, size), nil) +}