Skip to content

Commit

Permalink
Copy value received by MergeOlder/MergeNewer so caller can't trash th…
Browse files Browse the repository at this point in the history
…e merge result by modifying the contents.
  • Loading branch information
moodyjon authored and roylee17 committed Jun 6, 2022
1 parent 0241e18 commit 5f7b1f1
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions claimtrie/node/noderepo/pebble.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,17 @@ func (a *pooledMerger) Swap(i, j int) {
}

func (a *pooledMerger) MergeNewer(value []byte) error {
a.values = append(a.values, value)
vc := a.pool.Get().([]byte)[:0]
vc = append(vc, value...)
a.values = append(a.values, vc)
a.index = append(a.index, len(a.values))
return nil
}

func (a *pooledMerger) MergeOlder(value []byte) error {
a.values = append(a.values, value)
vc := a.pool.Get().([]byte)[:0]
vc = append(vc, value...)
a.values = append(a.values, vc)
a.index = append(a.index, -len(a.values))
return nil
}
Expand All @@ -53,6 +57,9 @@ func (a *pooledMerger) Finish(includesBase bool) ([]byte, io.Closer, error) {
}

func (a *pooledMerger) Close() error {
for i := range a.values {
a.pool.Put(a.values[i])
}
a.pool.Put(a.buffer)
return nil
}
Expand Down

0 comments on commit 5f7b1f1

Please sign in to comment.