Skip to content

Commit

Permalink
MultiSegmentArena: Fix release back into bufferpool
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
matheusd committed Jan 7, 2025
1 parent 567b3ac commit c17d814
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 2 additions & 1 deletion arena.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
Expand Down
2 changes: 2 additions & 0 deletions integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1825,6 +1825,8 @@ func BenchmarkDecode(b *testing.B) {
if err != nil {
b.Fatal(err)
}

msg.Release()
}
}
}
Expand Down

0 comments on commit c17d814

Please sign in to comment.