mobile: close node on error (#25643)

This commit is contained in:
Jakub Freebit 2022-08-31 19:31:16 +09:00 committed by GitHub
parent 362256ebff
commit 279afd7947
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -156,6 +156,7 @@ func NewNode(datadir string, config *NodeConfig) (stack *Node, _ error) {
// Parse the user supplied genesis spec if not mainnet // Parse the user supplied genesis spec if not mainnet
genesis = new(core.Genesis) genesis = new(core.Genesis)
if err := json.Unmarshal([]byte(config.EthereumGenesis), genesis); err != nil { if err := json.Unmarshal([]byte(config.EthereumGenesis), genesis); err != nil {
rawStack.Close()
return nil, fmt.Errorf("invalid genesis spec: %v", err) return nil, fmt.Errorf("invalid genesis spec: %v", err)
} }
// If we have the Ropsten testnet, hard code the chain configs too // If we have the Ropsten testnet, hard code the chain configs too
@ -196,11 +197,13 @@ func NewNode(datadir string, config *NodeConfig) (stack *Node, _ error) {
ethConf.DatabaseCache = config.EthereumDatabaseCache ethConf.DatabaseCache = config.EthereumDatabaseCache
lesBackend, err := les.New(rawStack, &ethConf) lesBackend, err := les.New(rawStack, &ethConf)
if err != nil { if err != nil {
rawStack.Close()
return nil, fmt.Errorf("ethereum init: %v", err) return nil, fmt.Errorf("ethereum init: %v", err)
} }
// If netstats reporting is requested, do it // If netstats reporting is requested, do it
if config.EthereumNetStats != "" { if config.EthereumNetStats != "" {
if err := ethstats.New(rawStack, lesBackend.ApiBackend, lesBackend.Engine(), config.EthereumNetStats); err != nil { if err := ethstats.New(rawStack, lesBackend.ApiBackend, lesBackend.Engine(), config.EthereumNetStats); err != nil {
rawStack.Close()
return nil, fmt.Errorf("netstats init: %v", err) return nil, fmt.Errorf("netstats init: %v", err)
} }
} }