Skip to content

Commit

Permalink
use copy bytes to avoid side effect
Browse files Browse the repository at this point in the history
  • Loading branch information
hadv committed May 19, 2023
1 parent 5568b76 commit 7e153f8
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions kvdb/flushable/flushable.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (w *Flushable) Put(key []byte, value []byte) error {
}

func (w *Flushable) put(key []byte, value []byte) {
w.modified.Put(key, common.CopyBytes(value))
w.modified.Put(common.CopyBytes(key), common.CopyBytes(value))
*w.sizeEstimation += len(key) + len(value) + 128
}

Expand Down Expand Up @@ -128,7 +128,7 @@ func (w *Flushable) Delete(key []byte) error {
}

func (w *Flushable) delete(key []byte) {
w.modified.Put(key, nil)
w.modified.Put(common.CopyBytes(key), nil)
*w.sizeEstimation += len(key) + 128 // it should be (len(key) - len(old value)), but we'd need to read old value
}

Expand Down

0 comments on commit 7e153f8

Please sign in to comment.