blockchain: call deinit in dtor

This ensures the io service that runs in another thread cannot
access data after it's deleted
This commit is contained in:
moneromooo-monero 2018-12-05 00:12:29 +00:00
parent e282e9fa40
commit 9e64a71e7d
No known key found for this signature in database
GPG key ID: 686F07454D6CEFC3
2 changed files with 15 additions and 7 deletions

View file

@ -171,6 +171,11 @@ Blockchain::Blockchain(tx_memory_pool& tx_pool) :
LOG_PRINT_L3("Blockchain::" << __func__); LOG_PRINT_L3("Blockchain::" << __func__);
} }
//------------------------------------------------------------------ //------------------------------------------------------------------
Blockchain::~Blockchain()
{
deinit();
}
//------------------------------------------------------------------
bool Blockchain::have_tx(const crypto::hash &id) const bool Blockchain::have_tx(const crypto::hash &id) const
{ {
LOG_PRINT_L3("Blockchain::" << __func__); LOG_PRINT_L3("Blockchain::" << __func__);
@ -550,16 +555,14 @@ bool Blockchain::deinit()
// as this should be called if handling a SIGSEGV, need to check // 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 // if m_db is a NULL pointer (and thus may have caused the illegal
// memory operation), otherwise we may cause a loop. // 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 try
{
if (m_db)
{ {
m_db->close(); m_db->close();
MTRACE("Local blockchain read/write activity stopped successfully"); MTRACE("Local blockchain read/write activity stopped successfully");
} }
}
catch (const std::exception& e) catch (const std::exception& e)
{ {
LOG_ERROR(std::string("Error closing blockchain db: ") + e.what()); LOG_ERROR(std::string("Error closing blockchain db: ") + e.what());

View file

@ -120,6 +120,11 @@ namespace cryptonote
*/ */
Blockchain(tx_memory_pool& tx_pool); Blockchain(tx_memory_pool& tx_pool);
/**
* @brief Blockchain destructor
*/
~Blockchain();
/** /**
* @brief Initialize the Blockchain state * @brief Initialize the Blockchain state
* *