Permalink
Browse files

blockchain: call deinit in dtor

This ensures the io service that runs in another thread cannot
access data after it's deleted
  • Loading branch information...
moneromooo-monero committed Dec 5, 2018
1 parent e282e9f commit 9e64a71e7d1fd70cdf94a3b78782ad06828362b3
Showing with 15 additions and 7 deletions.
  1. +10 −7 src/cryptonote_core/blockchain.cpp
  2. +5 −0 src/cryptonote_core/blockchain.h
@@ -171,6 +171,11 @@ Blockchain::Blockchain(tx_memory_pool& tx_pool) :
LOG_PRINT_L3("Blockchain::" << __func__);
}
//------------------------------------------------------------------
Blockchain::~Blockchain()
{
deinit();
}
//------------------------------------------------------------------
bool Blockchain::have_tx(const crypto::hash &id) const
{
LOG_PRINT_L3("Blockchain::" << __func__);
@@ -550,15 +555,13 @@ bool Blockchain::deinit()
// as this should be called if handling a SIGSEGV, need to check
// if m_db is a NULL pointer (and thus may have caused the illegal
// memory operation), otherwise we may cause a loop.
if (m_db == NULL)
{
throw DB_ERROR("The db pointer is null in Blockchain, the blockchain may be corrupt!");
}
try
{
m_db->close();
MTRACE("Local blockchain read/write activity stopped successfully");
if (m_db)
{
m_db->close();
MTRACE("Local blockchain read/write activity stopped successfully");
}
}
catch (const std::exception& e)
{
@@ -120,6 +120,11 @@ namespace cryptonote
*/
Blockchain(tx_memory_pool& tx_pool);
/**
* @brief Blockchain destructor
*/
~Blockchain();
/**
* @brief Initialize the Blockchain state
*

0 comments on commit 9e64a71

Please sign in to comment.