diff --git a/lightningd/subd.c b/lightningd/subd.c index 744d61529..05e08c082 100644 --- a/lightningd/subd.c +++ b/lightningd/subd.c @@ -438,6 +438,8 @@ static bool handle_peer_error(struct subd *sd, const u8 *msg, int fds[1]) /* Don't free sd; we may be about to free channel. */ sd->channel = NULL; + /* While it's cleaning up, this is not a leak! */ + notleak(sd); sd->errcb(channel, peer_fd, desc, err_for_them, disconnect, warning); return true; } @@ -641,6 +643,8 @@ static void destroy_subd(struct subd *sd) /* Clear any transient messages in billboard */ sd->billboardcb(channel, false, NULL); + /* While it's cleaning up, this is not a leak! */ + notleak(sd); sd->channel = NULL; /* We can be freed both inside msg handling, or spontaneously. */ @@ -928,11 +932,6 @@ void subd_release_channel(struct subd *owner, const void *channel) assert(owner->channel == channel); owner->channel = NULL; tal_free(owner); - } else { - /* Caller has reassigned channel->owner, so there's no pointer - * to this subd owner while it's freeing itself. If we - * ask memleak right now, it will complain! */ - notleak(owner); } }