Merge pull request #1485 from nspcc-dev/fix-get-for-boltdb

storage: fix Get for BoltDB, fix #1482
This commit is contained in:
Roman Khimov 2020-10-13 19:20:39 +03:00 committed by GitHub
commit 138d310c85
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -61,6 +61,12 @@ func (s *BoltDBStore) Get(key []byte) (val []byte, err error) {
err = s.db.View(func(tx *bbolt.Tx) error { err = s.db.View(func(tx *bbolt.Tx) error {
b := tx.Bucket(Bucket) b := tx.Bucket(Bucket)
val = b.Get(key) val = b.Get(key)
// Value from Get is only valid for the lifetime of transaction, #1482
if val != nil {
var valcopy = make([]byte, len(val))
copy(valcopy, val)
val = valcopy
}
return nil return nil
}) })
if val == nil { if val == nil {