Skip to content

Commit c17d814

Browse files
committed
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.
1 parent 567b3ac commit c17d814

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

‎arena.go‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ func (msa *MultiSegmentArena) demux(hdr streamHeader, data []byte, bp *bufferpoo
267267
msa.segs = append(msa.segs, make([]Segment, inc)...)
268268
}
269269

270+
rawData := data
270271
for i := SegmentID(0); i <= maxSeg; i++ {
271272
sz, err := hdr.segmentSize(SegmentID(i))
272273
if err != nil {
@@ -277,7 +278,7 @@ func (msa *MultiSegmentArena) demux(hdr streamHeader, data []byte, bp *bufferpoo
277278
msa.segs[i].id = i
278279
}
279280

280-
msa.rawData = data
281+
msa.rawData = rawData
281282
msa.bp = bp
282283
return nil
283284
}

‎integration_test.go‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1825,6 +1825,8 @@ func BenchmarkDecode(b *testing.B) {
18251825
if err != nil {
18261826
b.Fatal(err)
18271827
}
1828+
1829+
msg.Release()
18281830
}
18291831
}
18301832
}

0 commit comments

Comments
 (0)