Skip to content

Commit b45c597

Browse files
Use unique_ptr for pdbCopy (Db) and fix potential memory leak
1 parent 29ab96d commit b45c597

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

src/wallet/db.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ bool CDB::Rewrite(CWalletDBWrapper& dbw, const char* pszSkip)
522522
std::string strFileRes = strFile + ".rewrite";
523523
{ // surround usage of db with extra {}
524524
CDB db(dbw, "r");
525-
Db* pdbCopy = new Db(env->dbenv.get(), 0);
525+
std::unique_ptr<Db> pdbCopy = std::unique_ptr<Db>(new Db(env->dbenv.get(), 0));
526526

527527
int ret = pdbCopy->open(nullptr, // Txn pointer
528528
strFileRes.c_str(), // Filename
@@ -571,7 +571,6 @@ bool CDB::Rewrite(CWalletDBWrapper& dbw, const char* pszSkip)
571571
} else {
572572
pdbCopy->close(0);
573573
}
574-
delete pdbCopy;
575574
}
576575
if (fSuccess) {
577576
Db dbA(env->dbenv.get(), 0);

0 commit comments

Comments
 (0)