From c205970035db07cd3bd01d7e188dc671fa1f66ab Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Fri, 21 Jul 2023 07:15:48 +0930 Subject: [PATCH] connectd: fix transient memleak report. We left their_features dangling allocated off the hook_payload, whereas we explicitly move it to the peer, so steal/take it onto that. ``` - Node /tmp/ltests-gh55a_h2/test_connection_moved_1/lightning-2/ has memory leaks: [ { "backtrace": [ "/home/runner/work/lightning/lightning/ccan/ccan/tal/tal.c:477 (tal_alloc_)", "/home/runner/work/lightning/lightning/ccan/ccan/tal/tal.c:506 (tal_alloc_arr_)", "/home/runner/work/lightning/lightning/connectd/connectd_wiregen.c:410 (fromwire_connectd_peer_connected)", "/home/runner/work/lightning/lightning/lightningd/peer_control.c:1418 (peer_connected)", "/home/runner/work/lightning/lightning/lightningd/connect_control.c:592 (connectd_msg)", "/home/runner/work/lightning/lightning/lightningd/subd.c:557 (sd_msg_read)", "/home/runner/work/lightning/lightning/ccan/ccan/io/io.c:59 (next_plan)", "/home/runner/work/lightning/lightning/ccan/ccan/io/io.c:407 (do_plan)", "/home/runner/work/lightning/lightning/ccan/ccan/io/io.c:417 (io_ready)", "/home/runner/work/lightning/lightning/ccan/ccan/io/poll.c:453 (io_loop)", "/home/runner/work/lightning/lightning/lightningd/io_loop_with_timers.c:22 (io_loop_with_timers)", "/home/runner/work/lightning/lightning/lightningd/lightningd.c:1243 (main)" ], "label": "connectd/connectd_wiregen.c:410:u8[]", "parents": [ "lightningd/peer_control.c:1415:struct peer_connected_hook_payload", "lightningd/plugin_hook.c:260:struct plugin_hook_request **NOTLEAK**", "lightningd/plugin_hook.c:87:struct hook_instance *[] **NOTLEAK**" ], "value": "0x5582622b1ff8" } ] ``` Signed-off-by: Rusty Russell --- lightningd/peer_control.c | 4 ++-- lightningd/peer_control.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lightningd/peer_control.c b/lightningd/peer_control.c index 2a60b6b0c..8342c5161 100644 --- a/lightningd/peer_control.c +++ b/lightningd/peer_control.c @@ -1434,10 +1434,10 @@ void peer_connected(struct lightningd *ld, const u8 *msg) peer = peer_by_id(ld, &id); if (!peer) peer = new_peer(ld, 0, &id, &hook_payload->addr, - their_features, hook_payload->incoming); + take(their_features), hook_payload->incoming); else { tal_free(peer->their_features); - peer->their_features = tal_dup_talarr(peer, u8, their_features); + peer->their_features = tal_steal(peer, their_features); } /* We track this, because messages can race between connectd and us. diff --git a/lightningd/peer_control.h b/lightningd/peer_control.h index b9c0f3d10..9c69faac3 100644 --- a/lightningd/peer_control.h +++ b/lightningd/peer_control.h @@ -73,7 +73,7 @@ struct peer *find_peer_by_dbid(struct lightningd *ld, u64 dbid); struct peer *new_peer(struct lightningd *ld, u64 dbid, const struct node_id *id, const struct wireaddr_internal *addr, - const u8 *their_features, + const u8 *their_features TAKES, bool connected_incoming); /* Last one out deletes peer. Also removes from db. */