From 1e5c60e9c7c2ebf94e952fcc55729a7f65024a44 Mon Sep 17 00:00:00 2001 From: barton26 Date: Sun, 11 Jul 2021 22:46:33 -0400 Subject: [PATCH] [wallet] Close DB on error. Ref: https://github.com/bitcoin/bitcoin/pull/11017 I thought better and moved the trivial to another PR. This will be exclusively the DB change because it is a regression risk. --- src/wallet/db.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/wallet/db.cpp b/src/wallet/db.cpp index 860e75f40b..25e92b397e 100644 --- a/src/wallet/db.cpp +++ b/src/wallet/db.cpp @@ -101,8 +101,10 @@ bool CDBEnv::Open(fs::path pathEnv_) DB_RECOVER | nEnvFlags, S_IRUSR | S_IWUSR); - if (ret != 0) + if (ret != 0) { + dbenv.close(0); return error("CDB() : error %s (%d) opening database environment", DbEnv::strerror(ret), ret); + } fDbEnvInit = true; fMockDb = false; @@ -376,9 +378,9 @@ bool CDB::Rewrite(const string& strFile, const char* pszSkip) DB_BTREE, // Database type DB_CREATE, // Flags 0); - if (ret > 0) - { + if (ret > 0) { LogPrintf("Cannot create database file %s", strFileRes); + pdbCopy->close(0); fSuccess = false; } @@ -415,14 +417,15 @@ bool CDB::Rewrite(const string& strFile, const char* pszSkip) if (ret2 > 0) fSuccess = false; } - if (fSuccess) - { + if (fSuccess) { db.Close(); bitdb.CloseDb(strFile); if (pdbCopy->close(0)) fSuccess = false; - delete pdbCopy; + } else { + pdbCopy->close(0); } + delete pdbCopy; } if (fSuccess) {