+ make copies of the []bytes returned by goleveldb
- The byte strings returned by goleveldb aren't necessarily safe. See the following google group thread: https://groups.google.com/forum/#!topic/bleve/aHZ8gmihLiY This code change is based on the gist created here: https://groups.google.com/forum/#!topic/bleve/aHZ8gmihLiY
This commit is contained in:
parent
8e1c75a1cf
commit
3a70401835
@ -59,11 +59,17 @@ func (ldi *Iterator) Current() ([]byte, []byte, bool) {
|
||||
}
|
||||
|
||||
func (ldi *Iterator) Key() []byte {
|
||||
return ldi.iterator.Key()
|
||||
k := ldi.iterator.Key()
|
||||
rv := make([]byte, len(k))
|
||||
copy(rv, k)
|
||||
return rv
|
||||
}
|
||||
|
||||
func (ldi *Iterator) Value() []byte {
|
||||
return ldi.iterator.Value()
|
||||
v := ldi.iterator.Value()
|
||||
rv := make([]byte, len(v))
|
||||
copy(rv, v)
|
||||
return rv
|
||||
}
|
||||
|
||||
func (ldi *Iterator) Valid() bool {
|
||||
|
@ -52,7 +52,9 @@ func (ldbs *Store) get(key []byte) ([]byte, error) {
|
||||
if err == leveldb.ErrNotFound {
|
||||
return nil, nil
|
||||
}
|
||||
return b, err
|
||||
rv := make([]byte, len(b))
|
||||
copy(rv, b)
|
||||
return rv, err
|
||||
}
|
||||
|
||||
func (ldbs *Store) getWithSnapshot(key []byte, snapshot *leveldb.Snapshot) ([]byte, error) {
|
||||
@ -61,7 +63,9 @@ func (ldbs *Store) getWithSnapshot(key []byte, snapshot *leveldb.Snapshot) ([]by
|
||||
if err == leveldb.ErrNotFound {
|
||||
return nil, nil
|
||||
}
|
||||
return b, err
|
||||
rv := make([]byte, len(b))
|
||||
copy(rv, b)
|
||||
return rv, err
|
||||
}
|
||||
|
||||
func (ldbs *Store) set(key, val []byte) error {
|
||||
|
Loading…
Reference in New Issue
Block a user