Skip to content

Commit

Permalink
Track all refs
Browse files Browse the repository at this point in the history
  • Loading branch information
arjan-bal committed Jan 21, 2025
1 parent 4e0cf0b commit c4814b0
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions mem/buffers.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func NewBuffer(data *[]byte, pool BufferPool) Buffer {
b.data = *data
b.pool = pool
b.refs = refObjectPool.Get().(*atomic.Int32)
b.refs.Add(1)
b.Ref()
return b
}

Expand Down Expand Up @@ -140,9 +140,7 @@ func (b *buffer) ReadOnlyData() []byte {
}

func (b *buffer) Ref() {
if b.tracking {
b.refCallers = append(b.refCallers, string(debug.Stack()))
}
b.refCallers = append(b.refCallers, string(debug.Stack()))
if b.refs == nil {
panic("Cannot ref freed buffer")
}
Expand All @@ -154,9 +152,7 @@ func (b *buffer) Track() {
}

func (b *buffer) Free() {
if b.tracking {
b.freeCallers = append(b.freeCallers, string(debug.Stack()))
}
b.freeCallers = append(b.freeCallers, string(debug.Stack()))
if b.refs == nil {
panic("Cannot free freed buffer")
}
Expand Down Expand Up @@ -201,7 +197,7 @@ func (b *buffer) split(n int) (Buffer, Buffer) {
panic("Cannot split freed buffer")
}

b.refs.Add(1)
b.Ref()
split := newBuffer()
split.origData = b.origData
split.data = b.data[n:]
Expand Down

0 comments on commit c4814b0

Please sign in to comment.