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.h | |
parent | 6bc1eca01b2f88e081e71b783b3d45287700f8a5 (diff) |
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.h')
-rw-r--r-- | src/txdb.h | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/txdb.h b/src/txdb.h index 0cf7e2f1b8..e1096ffeba 100644 --- a/src/txdb.h +++ b/src/txdb.h @@ -60,7 +60,7 @@ public: uint256 GetBestBlock() const override; std::vector<uint256> GetHeadBlocks() const override; bool BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock) override; - CCoinsViewCursor *Cursor() const override; + std::unique_ptr<CCoinsViewCursor> Cursor() const override; //! Attempt to update from an older database format. Returns whether an error occurred. bool Upgrade(); @@ -74,6 +74,8 @@ public: class CCoinsViewDBCursor: public CCoinsViewCursor { public: + CCoinsViewDBCursor(CDBIterator* pcursorIn, const uint256 &hashBlockIn): + CCoinsViewCursor(hashBlockIn), pcursor(pcursorIn) {} ~CCoinsViewDBCursor() {} bool GetKey(COutPoint &key) const override; @@ -84,8 +86,6 @@ public: void Next() override; private: - CCoinsViewDBCursor(CDBIterator* pcursorIn, const uint256 &hashBlockIn): - CCoinsViewCursor(hashBlockIn), pcursor(pcursorIn) {} std::unique_ptr<CDBIterator> pcursor; std::pair<char, COutPoint> keyTmp; |