mirror of
https://github.com/dashpay/dash.git
synced 2024-12-27 21:12:48 +01:00
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
This commit is contained in:
commit
ae47724687
@ -101,8 +101,10 @@ bool CDBEnv::Open(const fs::path& pathIn)
|
|||||||
DB_RECOVER |
|
DB_RECOVER |
|
||||||
nEnvFlags,
|
nEnvFlags,
|
||||||
S_IRUSR | S_IWUSR);
|
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));
|
return error("CDBEnv::Open: Error %d opening database environment: %s\n", ret, DbEnv::strerror(ret));
|
||||||
|
}
|
||||||
|
|
||||||
fDbEnvInit = true;
|
fDbEnvInit = true;
|
||||||
fMockDb = false;
|
fMockDb = false;
|
||||||
@ -196,9 +198,9 @@ bool CDB::Recover(const std::string& filename, void *callbackDataIn, bool (*reco
|
|||||||
DB_BTREE, // Database type
|
DB_BTREE, // Database type
|
||||||
DB_CREATE, // Flags
|
DB_CREATE, // Flags
|
||||||
0);
|
0);
|
||||||
if (ret > 0)
|
if (ret > 0) {
|
||||||
{
|
|
||||||
LogPrintf("Cannot create database file %s\n", filename);
|
LogPrintf("Cannot create database file %s\n", filename);
|
||||||
|
pdbCopy->close(0);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -536,8 +538,10 @@ bool CDB::Rewrite(CWalletDBWrapper& dbw, const char* pszSkip)
|
|||||||
env->CloseDb(strFile);
|
env->CloseDb(strFile);
|
||||||
if (pdbCopy->close(0))
|
if (pdbCopy->close(0))
|
||||||
fSuccess = false;
|
fSuccess = false;
|
||||||
delete pdbCopy;
|
} else {
|
||||||
|
pdbCopy->close(0);
|
||||||
}
|
}
|
||||||
|
delete pdbCopy;
|
||||||
}
|
}
|
||||||
if (fSuccess) {
|
if (fSuccess) {
|
||||||
Db dbA(env->dbenv, 0);
|
Db dbA(env->dbenv, 0);
|
||||||
|
Loading…
Reference in New Issue
Block a user