lightningd: fix spurious memleak in peer_connected_serialize.
What changed, and why it matters
This commit fixes a harmless memory-accounting false alarm. A function that prepares data for a plugin hook was allocating small formatting strings under a long-lived object instead of a short-lived temporary context. Core Lightning's memory-leak detector could, in rare timing conditions, flag those strings as leaked. The fix moves the allocations to the temporary context so the detector is no longer upset. There is no user-visible bug, crash, or security vulnerability.
No security action required. Treat as normal code-quality/maintenance fix. If running a build that includes this path, updating removes a rare memleak warning from logs.
Security signals we found
memory-leak detector false positive
tal allocation context corrected
no attacker-controlled input path identified
no privilege boundary crossed
Evidence from the diff
In peer_connected_serialize(), fmt_wireaddr_internal() and fmt_wireaddr() were called with stream as the tal parent. The returned strings could outlive the function and be seen by the memleak scanner before stream was freed. The patch changes the parent to tmpctx, which is the conventional short-lived context for throwaway formatting strings in Core Lightning. This is a defensive cleanup of a spurious memleak report, not a use-after-free, double-free, or memory-exhaustion issue.
Changed components
lightningd/peer_control.cpeer_connected_serialize()plugin hook serialization for peer_connectedInspect captured patch +4 / −6
diff --git a/lightningd/peer_control.c b/lightningd/peer_control.c
index 2751769c..2ec8bea3 100644
--- a/lightningd/peer_control.c
+++ b/lightningd/peer_control.c
@@ -1322,13 +1322,11 @@ peer_connected_serialize(struct peer_connected_hook_payload *payload,
json_object_start(stream, "peer");
json_add_node_id(stream, "id", &payload->peer_id);
json_add_string(stream, "direction", payload->incoming ? "in" : "out");
- json_add_string(
- stream, "addr",
- fmt_wireaddr_internal(stream, &payload->addr));
+ json_add_string(stream, "addr",
+ fmt_wireaddr_internal(tmpctx, &payload->addr));
if (payload->remote_addr)
- json_add_string(
- stream, "remote_addr",
- fmt_wireaddr(stream, payload->remote_addr));
+ json_add_string(stream, "remote_addr",
+ fmt_wireaddr(tmpctx, payload->remote_addr));
/* Since this is start of hook, peer is always in table! */
json_add_hex_talarr(stream, "features",
peer_by_id(payload->ld, &payload->peer_id)
Why this scored 18/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.