diff options
author | Philip Kaufmann <phil.kaufmann@t-online.de> | 2014-09-28 16:11:17 +0200 |
---|---|---|
committer | Philip Kaufmann <phil.kaufmann@t-online.de> | 2014-10-01 08:48:23 +0200 |
commit | 870da77da632501e8eec58ed73e8f30549cc41e9 (patch) | |
tree | 405722d8204e9d212c98d08ed49dff99cefc8103 /src/wallet.cpp | |
parent | f606bb9bafafb12bcf9bc0834125c884da97f9e1 (diff) |
fix possible memory leaks in CWallet::EncryptWallet
- add missing deletes for pwalletdbEncryption
- add an assert before trying to reserve memory for pwalletdbEncryption
- add a destructor to CWallet, which ensures deletion of
pwalletdbEncryption on object destruction
Diffstat (limited to 'src/wallet.cpp')
-rw-r--r-- | src/wallet.cpp | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/src/wallet.cpp b/src/wallet.cpp index e69f59aacd..897f53b8b7 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -426,17 +426,25 @@ bool CWallet::EncryptWallet(const SecureString& strWalletPassphrase) mapMasterKeys[++nMasterKeyMaxID] = kMasterKey; if (fFileBacked) { + assert(!pwalletdbEncryption); pwalletdbEncryption = new CWalletDB(strWalletFile); - if (!pwalletdbEncryption->TxnBegin()) + if (!pwalletdbEncryption->TxnBegin()) { + delete pwalletdbEncryption; + pwalletdbEncryption = NULL; return false; + } pwalletdbEncryption->WriteMasterKey(nMasterKeyMaxID, kMasterKey); } if (!EncryptKeys(vMasterKey)) { - if (fFileBacked) + if (fFileBacked) { pwalletdbEncryption->TxnAbort(); - exit(1); //We now probably have half of our keys encrypted in memory, and half not...die and let the user reload their unencrypted wallet. + delete pwalletdbEncryption; + } + // We now probably have half of our keys encrypted in memory, and half not... + // die and let the user reload their unencrypted wallet. + exit(1); } // Encryption was introduced in version 0.4.0 @@ -444,8 +452,12 @@ bool CWallet::EncryptWallet(const SecureString& strWalletPassphrase) if (fFileBacked) { - if (!pwalletdbEncryption->TxnCommit()) - exit(1); //We now have keys encrypted in memory, but no on disk...die to avoid confusion and let the user reload their unencrypted wallet. + if (!pwalletdbEncryption->TxnCommit()) { + delete pwalletdbEncryption; + // We now have keys encrypted in memory, but no on disk... + // die to avoid confusion and let the user reload their unencrypted wallet. + exit(1); + } delete pwalletdbEncryption; pwalletdbEncryption = NULL; @@ -1068,7 +1080,7 @@ int64_t CWallet::GetWatchOnlyBalance() const nTotal += pcoin->GetAvailableWatchOnlyCredit(); } } - + return nTotal; } |