From e147445c08635d06f0da0ca4139a395eb8b982d8 Mon Sep 17 00:00:00 2001 From: Wilmer Paulino Date: Mon, 15 Jul 2019 13:32:37 -0700 Subject: [PATCH 1/2] lnd: prevent panic on nil neutrino cleanup A cleanup closure is not included when an error is returned, causing the defer to execute and triggering the following panic: panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x105da38] goroutine 1 [running]: github.com/lightningnetwork/lnd.Main(0x2083e40, 0xc0004f6db0) /home/user/lnd/lnd.go:208 +0x2bfa main.main() /home/user/lnd/cmd/lnd/main.go:14 +0x26 --- lnd.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lnd.go b/lnd.go index d1461511..250d8240 100644 --- a/lnd.go +++ b/lnd.go @@ -203,10 +203,10 @@ func Main() error { neutrinoBackend, neutrinoCleanUp, err := initNeutrinoBackend( mainChain.ChainDir, ) - defer neutrinoCleanUp() if err != nil { return err } + defer neutrinoCleanUp() neutrinoCS = neutrinoBackend } From 62d716d3c30f1b085a86cb2aa5ea1068658d55d6 Mon Sep 17 00:00:00 2001 From: Wilmer Paulino Date: Mon, 15 Jul 2019 13:42:01 -0700 Subject: [PATCH 2/2] chainregistry: properly close neutrino database upon errors --- chainregistry.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/chainregistry.go b/chainregistry.go index 529fcb10..a209cc66 100644 --- a/chainregistry.go +++ b/chainregistry.go @@ -713,6 +713,7 @@ func initNeutrinoBackend(chainDir string) (*neutrino.ChainService, func(), error cfg.NeutrinoMode.AssertFilterHeader, ) if err != nil { + db.Close() return nil, nil, err } @@ -754,6 +755,7 @@ func initNeutrinoBackend(chainDir string) (*neutrino.ChainService, func(), error neutrinoCS, err := neutrino.NewChainService(config) if err != nil { + db.Close() return nil, nil, fmt.Errorf("unable to create neutrino light "+ "client: %v", err) }