From 255f23679f3a3f1252ebe56eb1a4462336bf3d4a Mon Sep 17 00:00:00 2001 From: "Johan T. Halseth" Date: Mon, 9 Oct 2017 14:50:45 +0200 Subject: [PATCH] wallet: close db on Open() failure. This commit makes sure the wallet db is closed if the call to open the wallet fails, as subsequent calls to OpenExistingWallet would fail to open the already open database. --- wallet/loader.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/wallet/loader.go b/wallet/loader.go index 85015bf..f58ae9f 100644 --- a/wallet/loader.go +++ b/wallet/loader.go @@ -177,6 +177,13 @@ func (l *Loader) OpenExistingWallet(pubPassphrase []byte, canConsolePrompt bool) } w, err := Open(db, pubPassphrase, cbs, l.chainParams) if err != nil { + // If opening the wallet fails (e.g. because of wrong + // passphrase), we must close the backing database to + // allow future calls to walletdb.Open(). + e := db.Close() + if e != nil { + log.Warnf("Error closing database: %v", e) + } return nil, err } w.Start()