From c17d8141c900359341b50bdfee2c38284b1059a5 Mon Sep 17 00:00:00 2001 From: Matheus Degiovani Date: Tue, 7 Jan 2025 17:45:56 -0300 Subject: [PATCH] MultiSegmentArena: Fix release back into bufferpool This fixes a bug that was preventing correct release of buffers allocated by Decode() back to the global buffer pool. Previously, the data variable was overriden on the loop that splits the segments, preventing the correct tracking of the full data buffer and its subsequent return back to the buffer pool when the arena was released. This also adds a .Release() call to the Decode benchmark to better reflect the ability to reuse buffers. --- arena.go | 3 ++- integration_test.go | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/arena.go b/arena.go index 61440919..89b0df2c 100644 --- a/arena.go +++ b/arena.go @@ -267,6 +267,7 @@ func (msa *MultiSegmentArena) demux(hdr streamHeader, data []byte, bp *bufferpoo msa.segs = append(msa.segs, make([]Segment, inc)...) } + rawData := data for i := SegmentID(0); i <= maxSeg; i++ { sz, err := hdr.segmentSize(SegmentID(i)) if err != nil { @@ -277,7 +278,7 @@ func (msa *MultiSegmentArena) demux(hdr streamHeader, data []byte, bp *bufferpoo msa.segs[i].id = i } - msa.rawData = data + msa.rawData = rawData msa.bp = bp return nil } diff --git a/integration_test.go b/integration_test.go index 7abc59fb..fbdee38f 100644 --- a/integration_test.go +++ b/integration_test.go @@ -1825,6 +1825,8 @@ func BenchmarkDecode(b *testing.B) { if err != nil { b.Fatal(err) } + + msg.Release() } } }