Skip to content
This repository has been archived by the owner on Feb 1, 2021. It is now read-only.

Commit

Permalink
Close DB on error
Browse files Browse the repository at this point in the history
  • Loading branch information
Greg-Griffith committed May 1, 2019
1 parent 1becbcf commit 51f542f
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions src/wallet/db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -377,6 +380,7 @@ 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;
}

Expand Down Expand Up @@ -412,14 +416,20 @@ 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;
delete pdbCopy;
}
if (fSuccess)
{
db.Close();
bitdb.CloseDb(strFile);
if (pdbCopy->close(0))
{
fSuccess = false;
}
else
{
pdbCopy->close(0);
}
delete pdbCopy;
}
}
if (fSuccess)
{
Expand Down

0 comments on commit 51f542f

Please sign in to comment.