From 8b5c80f42ab3ebd10cebb5459c52ffbb99b467ee Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Thu, 9 Aug 2018 09:55:29 +0930 Subject: [PATCH] opening_control.c: make sure we always clean up in error cases. Especially by closing the file descriptors we were handed! Signed-off-by: Rusty Russell --- lightningd/opening_control.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/lightningd/opening_control.c b/lightningd/opening_control.c index 4f63538ce..a270ab3ab 100644 --- a/lightningd/opening_control.c +++ b/lightningd/opening_control.c @@ -459,16 +459,15 @@ static void opening_fundee_finished(struct subd *openingd, &uc->our_config.channel_reserve_satoshis)) { log_broken(uc->log, "bad OPENING_FUNDEE_REPLY %s", tal_hex(reply, reply)); - tal_free(uc); - return; + uncommitted_channel_disconnect(uc, "bad OPENING_FUNDEE_REPLY"); + goto failed; } /* openingd should never accept them funding channel in this case. */ if (peer_active_channel(uc->peer)) { log_broken(uc->log, "openingd accepted peer funding channel"); - /* Won't free peer, since has active channel */ - tal_free(uc); - return; + uncommitted_channel_disconnect(uc, "already have active channel"); + goto failed; } /* Consumes uc */ @@ -483,8 +482,8 @@ static void opening_fundee_finished(struct subd *openingd, &channel_info, feerate); if (!channel) { - tal_free(uc); - return; + uncommitted_channel_disconnect(uc, "Commit channel failed"); + goto failed; } log_debug(channel->log, "Watching funding tx %s", @@ -502,6 +501,12 @@ static void opening_fundee_finished(struct subd *openingd, subd_release_channel(openingd, uc); uc->openingd = NULL; tal_free(uc); + return; + +failed: + close(fds[0]); + close(fds[1]); + tal_free(uc); } static void opening_funder_failed(struct subd *openingd, const u8 *msg,