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 <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2023-07-21 07:15:48 +09:30
parent 745d3f6226
commit c205970035
2 changed files with 3 additions and 3 deletions

View File

@@ -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.

View File

@@ -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. */