mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
beacon/light: fix potential database iterator leaking
This commit is contained in:
parent
3b38b3b8ac
commit
751dc7a8a6
1 changed files with 3 additions and 2 deletions
|
|
@ -48,6 +48,8 @@ func newCanonicalStore[T any](db ethdb.Iteratee, keyPrefix []byte) (*canonicalSt
|
||||||
kl = len(keyPrefix)
|
kl = len(keyPrefix)
|
||||||
first = true
|
first = true
|
||||||
)
|
)
|
||||||
|
defer iter.Release()
|
||||||
|
|
||||||
for iter.Next() {
|
for iter.Next() {
|
||||||
if len(iter.Key()) != kl+8 {
|
if len(iter.Key()) != kl+8 {
|
||||||
log.Warn("Invalid key length in the canonical chain database", "key", fmt.Sprintf("%#x", iter.Key()))
|
log.Warn("Invalid key length in the canonical chain database", "key", fmt.Sprintf("%#x", iter.Key()))
|
||||||
|
|
@ -57,12 +59,11 @@ func newCanonicalStore[T any](db ethdb.Iteratee, keyPrefix []byte) (*canonicalSt
|
||||||
if first {
|
if first {
|
||||||
cs.periods.Start = period
|
cs.periods.Start = period
|
||||||
} else if cs.periods.End != period {
|
} else if cs.periods.End != period {
|
||||||
return nil, fmt.Errorf("Gap in the canonical chain database between periods %d and %d", cs.periods.End, period-1)
|
return nil, fmt.Errorf("gap in the canonical chain database between periods %d and %d", cs.periods.End, period-1)
|
||||||
}
|
}
|
||||||
first = false
|
first = false
|
||||||
cs.periods.End = period + 1
|
cs.periods.End = period + 1
|
||||||
}
|
}
|
||||||
iter.Release()
|
|
||||||
return cs, nil
|
return cs, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue