From f606bb9bafafb12bcf9bc0834125c884da97f9e1 Mon Sep 17 00:00:00 2001 From: Philip Kaufmann Date: Sun, 28 Sep 2014 16:09:19 +0200 Subject: 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") --- src/walletdb.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'src/walletdb.cpp') diff --git a/src/walletdb.cpp b/src/walletdb.cpp index a84f44db01..e13830a8f4 100644 --- a/src/walletdb.cpp +++ b/src/walletdb.cpp @@ -15,11 +15,11 @@ #include #include +#include #include -using namespace std; using namespace boost; - +using namespace std; static uint64_t nAccountingEntryNumber = 0; @@ -926,7 +926,7 @@ bool CWalletDB::Recover(CDBEnv& dbenv, std::string filename, bool fOnlyKeys) LogPrintf("Salvage(aggressive) found %u records\n", salvagedData.size()); bool fSuccess = allOK; - Db* pdbCopy = new Db(&dbenv.dbenv, 0); + boost::scoped_ptr pdbCopy(new Db(&dbenv.dbenv, 0)); int ret = pdbCopy->open(NULL, // Txn pointer filename.c_str(), // Filename "main", // Logical db name @@ -967,7 +967,6 @@ bool CWalletDB::Recover(CDBEnv& dbenv, std::string filename, bool fOnlyKeys) } ptxn->commit(0); pdbCopy->close(0); - delete pdbCopy; return fSuccess; } -- cgit v1.2.3