From 264c64380978d7b0bd3ecb56a861eb004cc58b01 Mon Sep 17 00:00:00 2001 From: Tim Ruffing Date: Thu, 3 May 2018 17:45:51 +0200 Subject: [PATCH] wallet: Reset BerkeleyDB handle after connection fails According to the BerkeleyDB docs, the DbEnv handle may not be accessed after close() has been called. This change ensures that we create a new handle after close() is called. This avoids a segfault when the first connection attempt fails and then a second connection attempt tries to call open() on the already closed DbEnv handle. --- src/wallet/db.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/wallet/db.cpp b/src/wallet/db.cpp index 10a06e4b9..adf694428 100644 --- a/src/wallet/db.cpp +++ b/src/wallet/db.cpp @@ -169,6 +169,7 @@ bool BerkeleyEnvironment::Open(bool retry) S_IRUSR | S_IWUSR); if (ret != 0) { dbenv->close(0); + Reset(); LogPrintf("BerkeleyEnvironment::Open: Error %d opening database environment: %s\n", ret, DbEnv::strerror(ret)); if (retry) { // try moving the database env out of the way