From 8e60b81c48f68a2ecd8aa3cc116ae3c7b7065fef Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Wed, 13 Dec 2017 14:04:19 +0000 Subject: cryptonote_core: fix db leak on error --- src/cryptonote_core/blockchain.cpp | 1 + src/cryptonote_core/cryptonote_core.cpp | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp index e774dd794..6e45417c0 100644 --- a/src/cryptonote_core/blockchain.cpp +++ b/src/cryptonote_core/blockchain.cpp @@ -321,6 +321,7 @@ bool Blockchain::init(BlockchainDB* db, const bool testnet, bool offline, const if (!db->is_open()) { LOG_ERROR("Attempted to init Blockchain with unopened DB"); + delete db; return false; } diff --git a/src/cryptonote_core/cryptonote_core.cpp b/src/cryptonote_core/cryptonote_core.cpp index 415657f9c..470a99aa4 100644 --- a/src/cryptonote_core/cryptonote_core.cpp +++ b/src/cryptonote_core/cryptonote_core.cpp @@ -377,7 +377,7 @@ namespace cryptonote // folder might not be a directory, etc, etc catch (...) { } - BlockchainDB* db = new_db(db_type); + std::unique_ptr db(new_db(db_type)); if (db == NULL) { LOG_ERROR("Attempted to use non-existent database type"); @@ -468,7 +468,7 @@ namespace cryptonote m_blockchain_storage.set_user_options(blocks_threads, blocks_per_sync, sync_mode, fast_sync); - r = m_blockchain_storage.init(db, m_testnet, m_offline, test_options); + r = m_blockchain_storage.init(db.release(), m_testnet, m_offline, test_options); r = m_mempool.init(); CHECK_AND_ASSERT_MES(r, false, "Failed to initialize memory pool"); -- cgit v1.2.3