mirror of
https://github.com/fluencelabs/tendermint
synced 2025-04-24 22:32:15 +00:00
libs/db: Fix the BoltDB Get and Iterator
BoltDB's accessors will return slices that are only valid for the lifetime of the transaction. This adds copies where required to prevent hard to debug crashes (among other things).
This commit is contained in:
parent
f46ed4aac8
commit
319ecb3005
@ -29,3 +29,4 @@
|
|||||||
|
|
||||||
### BUG FIXES:
|
### BUG FIXES:
|
||||||
- [libs/db] Fixed the BoltDB backend's Batch.Delete implementation (@Yawning)
|
- [libs/db] Fixed the BoltDB backend's Batch.Delete implementation (@Yawning)
|
||||||
|
- [libs/db] Fixed the BoltDB backend's Get and Iterator implementation (@Yawning)
|
||||||
|
@ -66,7 +66,9 @@ func (bdb *BoltDB) Get(key []byte) (value []byte) {
|
|||||||
key = nonEmptyKey(nonNilBytes(key))
|
key = nonEmptyKey(nonNilBytes(key))
|
||||||
err := bdb.db.View(func(tx *bbolt.Tx) error {
|
err := bdb.db.View(func(tx *bbolt.Tx) error {
|
||||||
b := tx.Bucket(bucket)
|
b := tx.Bucket(bucket)
|
||||||
value = b.Get(key)
|
if v := b.Get(key); v != nil {
|
||||||
|
value = append([]byte{}, v...)
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -312,12 +314,16 @@ func (itr *boltDBIterator) Next() {
|
|||||||
|
|
||||||
func (itr *boltDBIterator) Key() []byte {
|
func (itr *boltDBIterator) Key() []byte {
|
||||||
itr.assertIsValid()
|
itr.assertIsValid()
|
||||||
return itr.currentKey
|
return append([]byte{}, itr.currentKey...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (itr *boltDBIterator) Value() []byte {
|
func (itr *boltDBIterator) Value() []byte {
|
||||||
itr.assertIsValid()
|
itr.assertIsValid()
|
||||||
return itr.currentValue
|
var value []byte
|
||||||
|
if itr.currentValue != nil {
|
||||||
|
value = append([]byte{}, itr.currentValue...)
|
||||||
|
}
|
||||||
|
return value
|
||||||
}
|
}
|
||||||
|
|
||||||
func (itr *boltDBIterator) Close() {
|
func (itr *boltDBIterator) Close() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user