This fixes the potential memory leak caused by NewIterator() when GetBestBlock() throws an exception. (When compiled with clang, the parameters are evaluated from left to right)
refactor: call GetBestBlock() before NewIterator() #22266
pull endjkv wants to merge 1 commits into bitcoin:master from endjkv:master changing 1 files +2 −1-
endjkv commented at 8:24 AM on June 17, 2021: none
-
maflcko commented at 8:33 AM on June 17, 2021: member
Isn't this solved by std::make_unique already? #22263 (review)
Edit: Oh never mind, it is not.
- DrahtBot added the label Refactoring on Jun 17, 2021
- DrahtBot added the label UTXO Db and Indexes on Jun 17, 2021
-
DrahtBot commented at 6:08 PM on June 17, 2021: contributor
<!--e57a25ab6845829454e8d69fc972939a-->
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
<!--174a7506f384e20aa4161008e828411d-->
Conflicts
No conflicts as of last run.
-
Talkless commented at 6:50 PM on June 17, 2021: none
Edit: Oh never mind, it is not.
Right, it there would be no need for this PR if
CDBWrapper::NewIterator()would returnstd::unique_ptr. -
in src/txdb.cpp:197 in 6dc9aefea7 outdated
169 | @@ -170,7 +170,8 @@ bool CBlockTreeDB::ReadLastBlockFile(int &nFile) { 170 | 171 | CCoinsViewCursor *CCoinsViewDB::Cursor() const 172 | { 173 | - CCoinsViewDBCursor *i = new CCoinsViewDBCursor(const_cast<CDBWrapper&>(*m_db).NewIterator(), GetBestBlock()); 174 | + uint256 hashBestChain = GetBestBlock();
Talkless commented at 6:53 PM on June 17, 2021:nit: could be const
in src/txdb.cpp:174 in 6dc9aefea7 outdated
169 | @@ -170,7 +170,8 @@ bool CBlockTreeDB::ReadLastBlockFile(int &nFile) { 170 | 171 | CCoinsViewCursor *CCoinsViewDB::Cursor() const 172 | { 173 | - CCoinsViewDBCursor *i = new CCoinsViewDBCursor(const_cast<CDBWrapper&>(*m_db).NewIterator(), GetBestBlock()); 174 | + uint256 hashBestChain = GetBestBlock(); 175 | + CCoinsViewDBCursor *i = new CCoinsViewDBCursor(const_cast<CDBWrapper&>(*m_db).NewIterator(), hashBestChain);
Talkless commented at 6:56 PM on June 17, 2021:nit: could be
* const iif we are changing that line in any case :) . Pointer itself is never changed in the function.Talkless commented at 6:56 PM on June 17, 2021: noneConcept ACK
DrahtBot added the label Needs rebase on Jun 23, 2021refactor: call GetBestBlock() before NewIterator() ae29fffbc7endjkv force-pushed on Jun 24, 2021DrahtBot removed the label Needs rebase on Jun 24, 2021achow101 commented at 6:32 PM on October 12, 2022: memberClosing this as it has not had any activity in a while. If you are interested in continuing work on this, please leave a comment so that it can be reopened.
achow101 closed this on Oct 12, 2022bitcoin locked this on Oct 12, 2023Linked (view graph)
github-metadata-mirror
This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-17 18:14 UTC
This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-17 18:14 UTC
This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me
More mirrored repositories can be found on mirror.b10c.me