Skip to content

Commit f606bb9

Browse files
author
Philip Kaufmann
committed
fix a possible memory leak in CWalletDB::Recover
- convert pdbCopy into a boost::scoped_ptr to ensure memory gets freed in all cases (e.g. after "ret > 0")
1 parent e5836eb commit f606bb9

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

src/walletdb.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515

1616
#include <boost/filesystem.hpp>
1717
#include <boost/foreach.hpp>
18+
#include <boost/scoped_ptr.hpp>
1819
#include <boost/thread.hpp>
1920

20-
using namespace std;
2121
using namespace boost;
22-
22+
using namespace std;
2323

2424
static uint64_t nAccountingEntryNumber = 0;
2525

@@ -926,7 +926,7 @@ bool CWalletDB::Recover(CDBEnv& dbenv, std::string filename, bool fOnlyKeys)
926926
LogPrintf("Salvage(aggressive) found %u records\n", salvagedData.size());
927927

928928
bool fSuccess = allOK;
929-
Db* pdbCopy = new Db(&dbenv.dbenv, 0);
929+
boost::scoped_ptr<Db> pdbCopy(new Db(&dbenv.dbenv, 0));
930930
int ret = pdbCopy->open(NULL, // Txn pointer
931931
filename.c_str(), // Filename
932932
"main", // Logical db name
@@ -967,7 +967,6 @@ bool CWalletDB::Recover(CDBEnv& dbenv, std::string filename, bool fOnlyKeys)
967967
}
968968
ptxn->commit(0);
969969
pdbCopy->close(0);
970-
delete pdbCopy;
971970

972971
return fSuccess;
973972
}

0 commit comments

Comments
 (0)