Skip to content

Commit

Permalink
Changed LevelDB cursors to use scoped pointers to ensure destruction …
Browse files Browse the repository at this point in the history
…when going out of scope.

This corrects a bug where an exception thrown reading from the database causes the cursor to
be left open, which causes an assertion error to occur when the database is deleted (around
line 938 of init.cpp).
  • Loading branch information
Ross Nicoll committed Aug 16, 2014
1 parent 003bbd5 commit 5cbda4f
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/txdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ bool CBlockTreeDB::ReadLastBlockFile(int &nFile) {
}

bool CCoinsViewDB::GetStats(CCoinsStats &stats) {
leveldb::Iterator *pcursor = db.NewIterator();
boost::scoped_ptr<leveldb::Iterator> pcursor(db.NewIterator());
pcursor->SeekToFirst();

CHashWriter ss(SER_GETHASH, PROTOCOL_VERSION);
Expand Down Expand Up @@ -146,7 +146,6 @@ bool CCoinsViewDB::GetStats(CCoinsStats &stats) {
return error("%s : Deserialize or I/O error - %s", __func__, e.what());
}
}
delete pcursor;
stats.nHeight = mapBlockIndex.find(GetBestBlock())->second->nHeight;
stats.hashSerialized = ss.GetHash();
stats.nTotalAmount = nTotalAmount;
Expand Down Expand Up @@ -178,7 +177,7 @@ bool CBlockTreeDB::ReadFlag(const std::string &name, bool &fValue) {

bool CBlockTreeDB::LoadBlockIndexGuts()
{
leveldb::Iterator *pcursor = NewIterator();
boost::scoped_ptr<leveldb::Iterator> pcursor(NewIterator());

CDataStream ssKeySet(SER_DISK, CLIENT_VERSION);
ssKeySet << make_pair('b', uint256(0));
Expand Down Expand Up @@ -224,7 +223,6 @@ bool CBlockTreeDB::LoadBlockIndexGuts()
return error("%s : Deserialize or I/O error - %s", __func__, e.what());
}
}
delete pcursor;

return true;
}

0 comments on commit 5cbda4f

Please sign in to comment.