lightningd: parent watchman's formatted blockhash strings to tmpctx - #9363
Open
ksedgwic wants to merge 1 commit into
Open
lightningd: parent watchman's formatted blockhash strings to tmpctx#9363ksedgwic wants to merge 1 commit into
ksedgwic wants to merge 1 commit into
Conversation
json_add_string copies its value, so the strings fmt_bitcoin_blkid allocates in json_block_processed and json_getwatchmanheight are referenced by nothing once the call returns. They are parented to the response stream and freed with it, but the memleak scanner works by searching memory for pointers to each allocation: when a dev memleak check races an in-flight response, the unreferenced string is reported as a leak and fails the test run (seen in a liquid CI run of test_bwatch_add_watch_creates_datastore_entry). Parent them to tmpctx, the idiom used elsewhere. Fixes: ElementsProject#9362 Changelog-None
Andezion
approved these changes
Aug 3, 2026
Andezion
left a comment
Collaborator
There was a problem hiding this comment.
Do you know why parenting to response specifically trips the memleak scanner here, given response is itself reachable through the command's tal tree? Is it because the scan can race a not yet completed response object mid-write?
Collaborator
Author
|
json_add_string copies the bytes into the stream buffer, so nothing holds a pointer to the fmt_bitcoin_blkid string once the call returns; its only tie is the tal parent link. So yes -- when a dev-memleak check lands while a response is still in flight, the string is still allocated, referenced by nothing, and gets reported. Parenting to tmpctx closes that window. |
Lagrang3
approved these changes
Aug 4, 2026
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.
Fixes #9362 : the memleak scanner can flag the blockhash strings
watchman formats into its RPC responses -- json_add_string copies the
value, so nothing references the string afterward, and a dev memleak
check racing an in-flight response reports it as a leak. Parent them
to tmpctx, the idiom used elsewhere.
Changelog-None