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
This commit is contained in:
Wilmer Paulino 2019-07-15 13:32:37 -07:00
parent 616750184e
commit e147445c08
No known key found for this signature in database
GPG Key ID: 6DF57B9F9514972F

2
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
}