-
Notifications
You must be signed in to change notification settings - Fork 23
Open
Labels
bugSomething isn't workingSomething isn't working
Description
In my opinion code such as this is incorrect:
Lines 105 to 112 in 2cdd828
| for iter.Seek(prefix); iter.ValidForPrefix(prefix); iter.Next() { | |
| it := iter.Item() | |
| k := it.Key() | |
| if err := txn.Delete(k); err != nil { | |
| return fmt.Errorf("DeleteAuthor: failed to drop record %x: %w", k, err) | |
| } | |
| } |
Reasoning:
https://pkg.go.dev/github.com/dgraph-io/badger/v3#Item.Key:
Key is only valid as long as item is valid, or transaction is valid. If you need to use it outside its validity, please use KeyCopy.
https://pkg.go.dev/github.com/dgraph-io/badger/v3#Iterator.Item:
Item returns pointer to the current key-value pair. This item is only valid until it.Next() gets called.
In my opinion in this situation the item is only valid until the next iteration therefore key is illegaly reused. KeyCopy should be used instead. It is possible that txn.Delete(...) will remove other data. I imagine this is the case in other places in the code as well.
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working