From 89d231e4d1b704d7e4f812b79029aa528b1eb4ea Mon Sep 17 00:00:00 2001 From: Weixie Cui Date: Thu, 9 Jul 2026 20:00:00 +0800 Subject: [PATCH] eth: release state on error in stateAtTransaction Call the state release function on ApplyMessage failure and when the requested transaction index is out of range, avoiding leaked state snapshots on error paths. --- eth/state_accessor.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/eth/state_accessor.go b/eth/state_accessor.go index 7bcd83d581..802ff5a12a 100644 --- a/eth/state_accessor.go +++ b/eth/state_accessor.go @@ -267,11 +267,13 @@ func (eth *Ethereum) stateAtTransaction(ctx context.Context, block *types.Block, // Not yet the searched for transaction, execute on top of the current state statedb.SetTxContext(tx.Hash(), idx, uint32(idx+1)) if _, err := core.ApplyMessage(evm, msg, nil); err != nil { + release() return nil, vm.BlockContext{}, nil, nil, fmt.Errorf("transaction %#x failed: %v", tx.Hash(), err) } // Ensure any modifications are committed to the state // Only delete empty objects if EIP158/161 (a.k.a Spurious Dragon) is in effect statedb.Finalise(evm.ChainConfig().IsEIP158(block.Number())) } + release() return nil, vm.BlockContext{}, nil, nil, fmt.Errorf("transaction index %d out of range for block %#x", txIndex, block.Hash()) }