From c5d2ed8a85c03a1e403bd541c063750992edbcaf Mon Sep 17 00:00:00 2001 From: Greg-Griffith Date: Thu, 2 May 2019 04:31:08 +0900 Subject: [PATCH] Close DB on error --- src/wallet/db.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/wallet/db.cpp b/src/wallet/db.cpp index 5b42623f..bd85f127 100644 --- a/src/wallet/db.cpp +++ b/src/wallet/db.cpp @@ -111,7 +111,10 @@ bool CDBEnv::Open(const fs::path &pathIn) DB_CREATE | DB_INIT_LOCK | DB_INIT_LOG | DB_INIT_MPOOL | DB_INIT_TXN | DB_THREAD | DB_RECOVER | nEnvFlags, S_IRUSR | S_IWUSR); if (ret != 0) + { + dbenv->close(0); return error("CDBEnv::Open: Error %d opening database environment: %s\n", ret, DbEnv::strerror(ret)); + } fDbEnvInit = true; fMockDb = false; @@ -377,11 +380,13 @@ bool CDB::Rewrite(const std::string &strFile, const char *pszSkip) if (ret > 0) { LogPrintf("CDB::Rewrite: Can't create database file %s\n", strFileRes); + pdbCopy->close(0); fSuccess = false; } Dbc *pcursor = db.GetCursor(); if (pcursor) + { while (fSuccess) { CDataStream ssKey(SER_DISK, CLIENT_VERSION); @@ -412,15 +417,21 @@ bool CDB::Rewrite(const std::string &strFile, const char *pszSkip) if (ret2 > 0) fSuccess = false; } + } if (fSuccess) { db.Close(); bitdb.CloseDb(strFile); if (pdbCopy->close(0)) + { fSuccess = false; + } + else + { + pdbCopy->close(0); + } delete pdbCopy; } - } if (fSuccess) { Db dbA(bitdb.dbenv, 0);