Skip to content

Commit

Permalink
Merge pull request #12 from draganm/fix-returning-raw-mmaped-values
Browse files Browse the repository at this point in the history
copy values before returning them to keep them valid outside of transactions
  • Loading branch information
draganm authored Feb 2, 2023
2 parents 8deb557 + 25a4c8a commit 062a9fc
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions embedded/write_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,10 @@ func (w *writeTx) Get(path dbpath.Path) (v []byte, err error) {
return nil, errors.New("value not found")
}

return v, nil
copyOfValue := make([]byte, len(v))
copy(copyOfValue, v)

return copyOfValue, nil

}

Expand Down Expand Up @@ -284,10 +287,13 @@ func (w *writeTx) Iterator(path dbpath.Path) (it bolted.Iterator, err error) {
c := bucket.Cursor()
k, v := c.First()

copyOfValue := make([]byte, len(v))
copy(copyOfValue, v)

return &iterator{
c: c,
key: string(k),
value: v,
value: copyOfValue,
done: k == nil,
}, nil
}
Expand Down

0 comments on commit 062a9fc

Please sign in to comment.