aboutsummaryrefslogtreecommitdiff
path: root/src/wallet/db.cpp
diff options
context:
space:
mode:
authorJonas Schnelli <dev@jonasschnelli.ch>2017-08-15 21:24:07 +0200
committerJonas Schnelli <dev@jonasschnelli.ch>2017-08-15 21:24:21 +0200
commitae47724687a78572daba5bc113d99d03b7ab01d6 (patch)
tree349cd17838893086998b7d96c79d874f8e6d124f /src/wallet/db.cpp
parent64e66bb2628820903e6ca1074a1805b305c4565e (diff)
parent03bc719a85cb4928cb4b43d0bc4142f72cb01b23 (diff)
downloadbitcoin-ae47724687a78572daba5bc113d99d03b7ab01d6.tar.xz
Merge #11017: [wallet] Close DB on error.
03bc719a8 [wallet] Close DB on error. (Karl-Johan Alm) Pull request description: This PR intends to plug some leaks. It specifically implements adherence to the requirement in BDB to close a handle which failed to open (https://docs.oracle.com/cd/E17276_01/html/api_reference/C/dbopen.html): > The `DB->open()` method returns a non-zero error value on failure and 0 on success. If `DB->open()` fails, the `DB->close()` method must be called to discard the DB handle. Tree-SHA512: cc1f2b925ef3fd6de785f62108fbc79454443397f80707762acbc56757841d2c32b69c0234f87805571aa40c486da31f315ca4c607a2c7d1c97c82a01301e2a6
Diffstat (limited to 'src/wallet/db.cpp')
-rw-r--r--src/wallet/db.cpp12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/wallet/db.cpp b/src/wallet/db.cpp
index b12d46e40a..d2fe4866fa 100644
--- a/src/wallet/db.cpp
+++ b/src/wallet/db.cpp
@@ -101,8 +101,10 @@ bool CDBEnv::Open(const fs::path& pathIn)
DB_RECOVER |
nEnvFlags,
S_IRUSR | S_IWUSR);
- if (ret != 0)
+ 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;
@@ -196,9 +198,9 @@ bool CDB::Recover(const std::string& filename, void *callbackDataIn, bool (*reco
DB_BTREE, // Database type
DB_CREATE, // Flags
0);
- if (ret > 0)
- {
+ if (ret > 0) {
LogPrintf("Cannot create database file %s\n", filename);
+ pdbCopy->close(0);
return false;
}
@@ -536,8 +538,10 @@ bool CDB::Rewrite(CWalletDBWrapper& dbw, const char* pszSkip)
env->CloseDb(strFile);
if (pdbCopy->close(0))
fSuccess = false;
- delete pdbCopy;
+ } else {
+ pdbCopy->close(0);
}
+ delete pdbCopy;
}
if (fSuccess) {
Db dbA(env->dbenv, 0);