From ee939c8dcb883f6e941530737b5c4608de304044 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Fri, 5 Jan 2018 13:12:31 +1030 Subject: [PATCH] lightingd: fix memleak when we reload from db. We always arm the funding_lockin_cb, even if we don't need to. If we have an short_channel_id already from the db, this was replacing it and leaking the old one. Signed-off-by: Rusty Russell --- lightningd/peer_control.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lightningd/peer_control.c b/lightningd/peer_control.c index 51930333e..8e3676370 100644 --- a/lightningd/peer_control.c +++ b/lightningd/peer_control.c @@ -1502,10 +1502,13 @@ static enum watch_result funding_lockin_cb(struct peer *peer, loc = locate_tx(peer, peer->ld->topology, &txid); - peer->scid = tal(peer, struct short_channel_id); - peer->scid->blocknum = loc->blkheight; - peer->scid->txnum = loc->index; - peer->scid->outnum = peer->funding_outnum; + /* If we restart, we could already have peer->scid from database */ + if (!peer->scid) { + peer->scid = tal(peer, struct short_channel_id); + peer->scid->blocknum = loc->blkheight; + peer->scid->txnum = loc->index; + peer->scid->outnum = peer->funding_outnum; + } tal_free(loc); /* In theory, it could have been buried before we got back