Skip to content

Commit

Permalink
fix: correctly close iterator in 07-tendermint store (#3022)
Browse files Browse the repository at this point in the history
* fix closing iterator in 07-tendermint

* maintain defer pattern but use new variable to avoiid reassignment issues
  • Loading branch information
damiannolan authored Jan 18, 2023
1 parent a6d251e commit 8b03197
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions modules/light-clients/07-tendermint/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,11 @@ func IterateConsensusMetadata(store sdk.KVStore, cb func(key, val []byte) bool)
}

// iterate over iteration keys
iterator = sdk.KVStorePrefixIterator(store, []byte(KeyIterateConsensusStatePrefix))
iter := sdk.KVStorePrefixIterator(store, []byte(KeyIterateConsensusStatePrefix))

defer iterator.Close()
for ; iterator.Valid(); iterator.Next() {
if cb(iterator.Key(), iterator.Value()) {
defer iter.Close()
for ; iter.Valid(); iter.Next() {
if cb(iter.Key(), iter.Value()) {
break
}
}
Expand Down

0 comments on commit 8b03197

Please sign in to comment.