mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-20 07:09:15 +01:00
refactor: wrap CCoinsViewCursor in unique_ptr
Specifically with CCoinsViewDB, if a raw cursor is allocated and not freed, a cryptic leveldb assertion failure occurs on CCoinsViewDB destruction. See: https://github.com/google/leveldb/issues/142#issuecomment-414418135
This commit is contained in:
@@ -168,9 +168,10 @@ bool CBlockTreeDB::ReadLastBlockFile(int &nFile) {
|
||||
return Read(DB_LAST_BLOCK, nFile);
|
||||
}
|
||||
|
||||
CCoinsViewCursor *CCoinsViewDB::Cursor() const
|
||||
std::unique_ptr<CCoinsViewCursor> CCoinsViewDB::Cursor() const
|
||||
{
|
||||
CCoinsViewDBCursor *i = new CCoinsViewDBCursor(const_cast<CDBWrapper&>(*m_db).NewIterator(), GetBestBlock());
|
||||
auto i = std::make_unique<CCoinsViewDBCursor>(
|
||||
const_cast<CDBWrapper&>(*m_db).NewIterator(), GetBestBlock());
|
||||
/* It seems that there are no "const iterators" for LevelDB. Since we
|
||||
only need read operations on it, use a const-cast to get around
|
||||
that restriction. */
|
||||
|
||||
Reference in New Issue
Block a user