null out batch txn pointer as needed (BlockchainLMDB)

This commit is contained in:
Thomas Winget 2015-05-18 05:45:15 -04:00
parent 7b7ef73c15
commit b0d849e0a4
No known key found for this signature in database
GPG Key ID: 58131A160789E630
1 changed files with 5 additions and 4 deletions

View File

@ -760,6 +760,7 @@ BlockchainLMDB::BlockchainLMDB(bool batch_transactions)
m_batch_transactions = batch_transactions;
m_write_txn = nullptr;
m_write_batch_txn = nullptr;
m_batch_active = false;
m_height = 0;
}
@ -1791,10 +1792,8 @@ void BlockchainLMDB::batch_start()
throw0(DB_ERROR("batch transaction attempted, but m_write_txn already in use"));
check_open();
if (m_write_batch_txn == nullptr)
{
m_write_batch_txn = new mdb_txn_safe();
}
// NOTE: need to make sure it's destroyed properly when done
if (mdb_txn_begin(m_env, NULL, 0, *m_write_batch_txn))
throw0(DB_ERROR("Failed to create a transaction for the db"));
@ -1846,6 +1845,7 @@ void BlockchainLMDB::batch_stop()
// for destruction of batch transaction
m_write_txn = nullptr;
delete m_write_batch_txn;
m_write_batch_txn = nullptr;
m_batch_active = false;
LOG_PRINT_L3("batch transaction: end");
}
@ -1863,6 +1863,7 @@ void BlockchainLMDB::batch_abort()
// explicitly call in case mdb_env_close() (BlockchainLMDB::close()) called before BlockchainLMDB destructor called.
m_write_batch_txn->abort();
m_batch_active = false;
m_write_batch_txn = nullptr;
LOG_PRINT_L3("batch transaction: aborted");
}