trie: fix two issues in trie iterator (#24539)
* trie: fix memory leak in trie iterator In the trie iterator, live nodes are tracked in a stack while iterating. Popped node states should be explictly set to nil in order to get garbage-collected. * trie: fix empty trie iterator
This commit is contained in:
@ -29,6 +29,19 @@ import (
|
||||
"github.com/ethereum/go-ethereum/ethdb/memorydb"
|
||||
)
|
||||
|
||||
func TestEmptyIterator(t *testing.T) {
|
||||
trie := newEmpty()
|
||||
iter := trie.NodeIterator(nil)
|
||||
|
||||
seen := make(map[string]struct{})
|
||||
for iter.Next(true) {
|
||||
seen[string(iter.Path())] = struct{}{}
|
||||
}
|
||||
if len(seen) != 0 {
|
||||
t.Fatal("Unexpected trie node iterated")
|
||||
}
|
||||
}
|
||||
|
||||
func TestIterator(t *testing.T) {
|
||||
trie := newEmpty()
|
||||
vals := []struct{ k, v string }{
|
||||
|
Reference in New Issue
Block a user