From 086acd5bc1ad47d07028b42687a7c7e1f3e81a74 Mon Sep 17 00:00:00 2001 From: Marco Pracucci Date: Thu, 22 Apr 2021 15:42:26 +0200 Subject: [PATCH] Fix race condition in pool.BucketedBytes Signed-off-by: Marco Pracucci --- pkg/pool/pool.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pkg/pool/pool.go b/pkg/pool/pool.go index f0bd580042f..cbd034e9e7c 100644 --- a/pkg/pool/pool.go +++ b/pkg/pool/pool.go @@ -112,12 +112,13 @@ func (p *BucketedBytes) Put(b *[]byte) { continue } *b = (*b)[:0] - p.mtx.Lock() - defer p.mtx.Unlock() p.buckets[i].Put(b) break } + p.mtx.Lock() + defer p.mtx.Unlock() + // We could assume here that our users will not make the slices larger // but lets be on the safe side to avoid an underflow of p.usedTotal. sz := uint64(cap(*b))