Skip to content

Commit

Permalink
[wallet] Close DB on error.
Browse files Browse the repository at this point in the history
  • Loading branch information
barton2526 committed Jul 12, 2021
1 parent 57bf77b commit bca2f93
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/wallet/db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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)
{
Expand Down

0 comments on commit bca2f93

Please sign in to comment.