diff options
author | James O'Beirne <james.obeirne@pm.me> | 2021-06-16 16:27:20 -0400 |
---|---|---|
committer | James O'Beirne <james.obeirne@pm.me> | 2021-06-17 09:47:08 -0400 |
commit | 615c1adfb07b9b466173166dc2e53ace540e4b32 (patch) | |
tree | 4261a142c5886d8ec309292c0b91bd78e6861b8c /src/txdb.cpp | |
parent | 6bc1eca01b2f88e081e71b783b3d45287700f8a5 (diff) | |
download | bitcoin-615c1adfb07b9b466173166dc2e53ace540e4b32.tar.xz |
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
Diffstat (limited to 'src/txdb.cpp')
-rw-r--r-- | src/txdb.cpp | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/src/txdb.cpp b/src/txdb.cpp index 762f71feb1..bd0e9f7317 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -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. */ |