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 c5d2ed8
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion 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,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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit c5d2ed8

Please sign in to comment.