Skip to content

Commit 03bc719

Browse files
committed
[wallet] Close DB on error.
1 parent 929fd72 commit 03bc719

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/wallet/db.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,10 @@ bool CDBEnv::Open(const fs::path& pathIn)
101101
DB_RECOVER |
102102
nEnvFlags,
103103
S_IRUSR | S_IWUSR);
104-
if (ret != 0)
104+
if (ret != 0) {
105+
dbenv->close(0);
105106
return error("CDBEnv::Open: Error %d opening database environment: %s\n", ret, DbEnv::strerror(ret));
107+
}
106108

107109
fDbEnvInit = true;
108110
fMockDb = false;
@@ -196,9 +198,9 @@ bool CDB::Recover(const std::string& filename, void *callbackDataIn, bool (*reco
196198
DB_BTREE, // Database type
197199
DB_CREATE, // Flags
198200
0);
199-
if (ret > 0)
200-
{
201+
if (ret > 0) {
201202
LogPrintf("Cannot create database file %s\n", filename);
203+
pdbCopy->close(0);
202204
return false;
203205
}
204206

@@ -536,8 +538,10 @@ bool CDB::Rewrite(CWalletDBWrapper& dbw, const char* pszSkip)
536538
env->CloseDb(strFile);
537539
if (pdbCopy->close(0))
538540
fSuccess = false;
539-
delete pdbCopy;
541+
} else {
542+
pdbCopy->close(0);
540543
}
544+
delete pdbCopy;
541545
}
542546
if (fSuccess) {
543547
Db dbA(env->dbenv, 0);

0 commit comments

Comments
 (0)