Skip to content

Commit 0c4b20f

Browse files
committed
[Wallet] Close DB on error
1 parent f15a167 commit 0c4b20f

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/wallet/db.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,10 @@ bool CDBEnv::Open(const fs::path& pathIn)
104104
DB_RECOVER |
105105
nEnvFlags,
106106
S_IRUSR | S_IWUSR);
107-
if (ret != 0)
107+
if (ret != 0) {
108+
dbenv->close(0);
108109
return error("CDBEnv::Open : Error %d opening database environment: %s\n", ret, DbEnv::strerror(ret));
110+
}
109111

110112
fDbEnvInit = true;
111113
fMockDb = false;
@@ -199,6 +201,7 @@ bool CDB::Recover(const std::string& filename, void *callbackDataIn, bool (*reco
199201
0);
200202
if (ret > 0) {
201203
LogPrintf("Cannot create database file %s\n", filename);
204+
pdbCopy->close(0);
202205
return false;
203206
}
204207

@@ -533,8 +536,10 @@ bool CDB::Rewrite(CWalletDBWrapper& dbw, const char* pszSkip)
533536
env->CloseDb(strFile);
534537
if (pdbCopy->close(0))
535538
fSuccess = false;
536-
delete pdbCopy;
539+
} else {
540+
pdbCopy->close(0);
537541
}
542+
delete pdbCopy;
538543
}
539544
if (fSuccess) {
540545
Db dbA(env->dbenv, 0);

0 commit comments

Comments
 (0)