From a21da9058bf33939ce07c2eef8ba9b2da508192b Mon Sep 17 00:00:00 2001 From: oneiric Date: Sat, 22 Sep 2018 22:03:36 +0000 Subject: Wallet: use unique_ptr for WalletImpl members Use unique_ptr to manage WalletImpl internals, rather than raw pointers. --- src/wallet/api/wallet.cpp | 26 ++++++++++---------------- src/wallet/api/wallet.h | 12 ++++++------ 2 files changed, 16 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/wallet/api/wallet.cpp b/src/wallet/api/wallet.cpp index 8b25096a2..b0e5fa37f 100644 --- a/src/wallet/api/wallet.cpp +++ b/src/wallet/api/wallet.cpp @@ -376,15 +376,15 @@ WalletImpl::WalletImpl(NetworkType nettype, uint64_t kdf_rounds) , m_rebuildWalletCache(false) , m_is_connected(false) { - m_wallet = new tools::wallet2(static_cast(nettype), kdf_rounds, true); - m_history = new TransactionHistoryImpl(this); - m_wallet2Callback = new Wallet2CallbackImpl(this); + m_wallet = std::make_unique(static_cast(nettype), kdf_rounds, true); + m_history = std::make_unique(this); + m_wallet2Callback = std::make_unique(this); m_wallet->callback(m_wallet2Callback); m_refreshThreadDone = false; m_refreshEnabled = false; - m_addressBook = new AddressBookImpl(this); - m_subaddress = new SubaddressImpl(this); - m_subaddressAccount = new SubaddressAccountImpl(this); + m_addressBook = std::make_unique(this); + m_subaddress = std::make_unique(this); + m_subaddressAccount = std::make_unique(this); m_refreshIntervalMillis = DEFAULT_REFRESH_INTERVAL_MILLIS; @@ -405,12 +405,6 @@ WalletImpl::~WalletImpl() close(false); // do not store wallet as part of the closing activities // Stop refresh thread stopRefresh(); - delete m_wallet2Callback; - delete m_history; - delete m_addressBook; - delete m_subaddress; - delete m_subaddressAccount; - delete m_wallet; LOG_PRINT_L1(__FUNCTION__ << " finished"); } @@ -1551,22 +1545,22 @@ void WalletImpl::disposeTransaction(PendingTransaction *t) TransactionHistory *WalletImpl::history() { - return m_history; + return m_history.get(); } AddressBook *WalletImpl::addressBook() { - return m_addressBook; + return m_addressBook.get(); } Subaddress *WalletImpl::subaddress() { - return m_subaddress; + return m_subaddress.get(); } SubaddressAccount *WalletImpl::subaddressAccount() { - return m_subaddressAccount; + return m_subaddressAccount.get(); } void WalletImpl::setListener(WalletListener *l) diff --git a/src/wallet/api/wallet.h b/src/wallet/api/wallet.h index e3a300317..b2317b9ba 100644 --- a/src/wallet/api/wallet.h +++ b/src/wallet/api/wallet.h @@ -215,16 +215,16 @@ private: friend class SubaddressImpl; friend class SubaddressAccountImpl; - tools::wallet2 * m_wallet; + std::unique_ptr m_wallet; mutable boost::mutex m_statusMutex; mutable int m_status; mutable std::string m_errorString; std::string m_password; - TransactionHistoryImpl * m_history; - Wallet2CallbackImpl * m_wallet2Callback; - AddressBookImpl * m_addressBook; - SubaddressImpl * m_subaddress; - SubaddressAccountImpl * m_subaddressAccount; + std::unique_ptr m_history; + std::unique_ptr m_wallet2Callback; + std::unique_ptr m_addressBook; + std::unique_ptr m_subaddress; + std::unique_ptr m_subaddressAccount; // multi-threaded refresh stuff std::atomic m_refreshEnabled; -- cgit v1.2.3