Skip to content

Commit

Permalink
lightningd: mark subd->conn notleak() properly in transition.
Browse files Browse the repository at this point in the history
Since subd is temporarily unreferenced, and our leak detection goes up
to the highest unreferenced parent, it complains about openingd->conn.

The correct fix is to catch this where we detach the subd:

```
DEBUG:root:{
  "id": 1,
  "result": {
    "leaks": [
      {
        "value": "0x556e0445d8f8",
        "label": "ccan/ccan/io/io.c:91:struct io_conn",
        "backtrace": [
          "ccan/ccan/tal/tal.c:442 (tal_alloc_)",
          "ccan/ccan/io/io.c:91 (io_new_conn_)",
          "lightningd/subd.c:774 (new_subd)",
          "lightningd/subd.c:828 (new_channel_subd_)",
          "lightningd/opening_control.c:872 (peer_start_openingd)",
          "lightningd/peer_control.c:1311 (peer_active)",
          "lightningd/connect_control.c:458 (connectd_msg)",
          "lightningd/subd.c:557 (sd_msg_read)",
          "lightningd/subd.c:357 (read_fds)",
          "ccan/ccan/io/io.c:59 (next_plan)",
          "ccan/ccan/io/io.c:407 (do_plan)",
          "ccan/ccan/io/io.c:417 (io_ready)",
          "ccan/ccan/io/poll.c:453 (io_loop)",
          "lightningd/io_loop_with_timers.c:22 (io_loop_with_timers)",
          "lightningd/lightningd.c:1182 (main)",
          "../csu/libc-start.c:308 (__libc_start_main)"
        ],
        "parents": [
          "lightningd/lightningd.c:107:struct lightningd"
        ]
      }
    ]
  }
}
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
  • Loading branch information
rustyrussell committed Jul 4, 2022
1 parent 46d6312 commit ab09252
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lightningd/opening_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,11 @@ static void openingd_failed(struct subd *openingd, const u8 *msg,
{
char *desc;

/* Since we're detaching from uc, we'll be unreferenced until
* our imminent exit (as will our parent, openingd->conn). */
notleak(openingd);
notleak(openingd->conn);

if (!fromwire_openingd_failed(msg, msg, &desc)) {
log_broken(uc->log,
"bad OPENINGD_FAILED %s",
Expand Down Expand Up @@ -676,8 +681,6 @@ openchannel_hook_final(struct openchannel_hook_payload *payload STEALS)
} else
upfront_shutdown_script_wallet_index = NULL;

/* In case peer goes away right now, mark openingd notleak() */
notleak(openingd);
subd_send_msg(openingd,
take(towire_openingd_got_offer_reply(NULL, errmsg,
our_upfront_shutdown_script,
Expand Down

0 comments on commit ab09252

Please sign in to comment.