Repository navigation
fix the leaks of the wallet and its queries, and the range of get_blocks_by_range - #184
Open
mycomputercrashsalot wants to merge 9 commits into
Open
mycomputercrashsalot wants to merge 9 commits into
mycomputercrashsalot wants to merge 9 commits into
Conversation
mycomputercrashsalot
force-pushed
the
todo-fixes
branch
from
November 8, 2026 07:34
abaa8c3 to
2ae07aa
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Six fixes for problems that monero-c's TODO documents against monero-cpp, each measured before and after. The leak evidence is malloc-zone accounting per call on macOS (LeakSanitizer does not exist there); the Linux CI can confirm with LSan.
utils: limit the json nesting that deserialize accepts (
aa3b2c4)gen_utils::deserialize()parses with boost'sread_json(), which recurses once per level: a daemon that answers with 100000 levels of[[[[...overflows the stack and ends the process (20000 levels pass, 100000 crash; a thread with the 1 MB stack that is the Windows default crashes at 8000). The fix scans the nesting before parsing and throwsInvalid JSONabove 64 levels, the same limit monero-c checks at its boundary.wallet: free the wallet when a factory throws (
8ea5ff8)open_wallet(), thecreate_wallet*()functions ofmonero_wallet_fulland the factories ofmonero_wallet_keysallocate with a rawnew, so an exception after the allocation leaks the wallet and itswallet2: every open with a wrong password leaks about 200 KB (measured 246,511 bytes; 257,439 for a create over an existing file). The factories hold the wallet in astd::unique_ptrandrelease()on return: both shapes leak 0 now. The// TODO: delete wallet pointer if exceptioncomment at monero_wallet_full.cpp:1159 is done.wallet: free the txs that get_txs filters out (
068e12f)get_txs_aux()erases the txs that fail a transfer, input or output query without releasing them (9.7 KB for 5 txs, 243 KB for 100, per call). The erased tx detaches from its block first —monero_utils::free(tx)would reset the links of the sibling txs that stay in the result — then drops its reference, which frees it when nothing else holds it.utils: free the miner tx, the io of a plain tx and the input query of a tx query (
f07f686)monero_utils::free(block)left the miner tx of the block, the inputs and outputs of a plainmonero_txas the daemon builds it, and the input query of a tx query unfreed: 4,976 bytes per block and 1,600 per query. A commonfree_tx_links()releases them; on the live wallet matrix the query shapes that kept 28,080 to 35,520 bytes per call keep 0. Onlyshared_ptr::reset()is used, so a link that a caller already reset is an idempotent no-op — nothing is freed twice.wallet: free the copied output query when the call throws too (
11d809a)get_outputs_aux()copies the tx query and frees the copy on return, but a throw between the copy and the return leaked it, and the copy of an input query points back at the copy of the tx query (3,200 bytes per call on{"txQuery":{"inputQuery":{"isSpent":true}}}). The free runs in a scope-leave handler right after the copy, the idiomget_txs_aux()uses.daemon: clamp and chunk the range of get_blocks_by_range (
c30a46a)The loop that lists every height never ends when
endisUINT64_MAX, and it fills a vector with each height before the first request. The end is clamped to the top of the chain, and the heights are fetched in chunks of 1000, so no vector of the whole range is built. Probed on a regtest chain of 1051 blocks:range(0, UINT64_MAX)returns all 1051 (two chunks, no hang), a normal range returns the same blocks as before, an inverted range is empty.