Skip to content

Commit

Permalink
rpc_util: add capacity checks for all buffer pool sizes
Browse files Browse the repository at this point in the history
- It's not required, as it's guaranteed outside the pool, but it seems safer.
  • Loading branch information
hueypark committed May 23, 2023
1 parent fe1294f commit 5535416
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions shared_buffer_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,8 @@ type bufferPool struct {
func (p *bufferPool) Get(size int) []byte {
bs := p.Pool.Get().(*[]byte)

// If default size is 0. It means this pool is fallback pool.
// Therefore, we need to make a new one if the requested size is larger than the buffer.
if p.defaultSize == 0 {
if cap(*bs) < size {
*bs = make([]byte, size)
}
if cap(*bs) < size {
*bs = make([]byte, size)
}

return (*bs)[:size]
Expand Down

0 comments on commit 5535416

Please sign in to comment.