Skip to content

Commit

Permalink
Copy k/v pairs since tmlibs doesn't
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudhead authored and melekes committed Feb 1, 2018
1 parent 32bef9e commit 68a7643
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion nodedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,17 @@ func (ndb *nodeDB) traversePrefix(prefix []byte, fn func(k, v []byte)) {
defer itr.Close()

for ; itr.Valid(); itr.Next() {
fn(itr.Key(), itr.Value())
// We have to create a copy of the k/v pair here, since we can't
// guarantee that the memory isn't re-used by one of the backends.
val := itr.Value()
v := make([]byte, len(val))
copy(v, val)

key := itr.Key()
k := make([]byte, len(key))
copy(k, key)

fn(k, v)
}
}

Expand Down

0 comments on commit 68a7643

Please sign in to comment.