channeld: stop taken() leak.

I saw this message:

```
lightning_channeld: outstanding taken(): channeld/channeld.c:3087:blinding
lightning_channeld: outstanding taken(): channeld/channeld.c:3087:blinding
lightning_channeld: outstanding taken(): channeld/channeld.c:3087:blinding
```

The caller does take(blinding), but blinding can be NULL.  We should
move the code around to do the take() earlier anyway.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2021-01-06 16:10:36 +10:30 committed by Christian Decker
parent 0726d2912e
commit 106afd005f
1 changed files with 12 additions and 9 deletions

View File

@ -496,6 +496,18 @@ static enum channel_add_err add_htlc(struct channel *channel,
htlc->amount = amount;
htlc->state = state;
htlc->rhash = *payment_hash;
if (blinding)
htlc->blinding = tal_dup(htlc, struct pubkey, blinding);
else {
/* Can be taken, even if NULL. */
taken(blinding);
htlc->blinding = NULL;
}
htlc->failed = NULL;
htlc->r = NULL;
htlc->routing = tal_dup_arr(htlc, u8, routing, TOTAL_PACKET_SIZE(ROUTING_INFO_SIZE), 0);
/* FIXME: Change expiry to simple u32 */
/* BOLT #2:
@ -510,15 +522,6 @@ static enum channel_add_err add_htlc(struct channel *channel,
return CHANNEL_ERR_INVALID_EXPIRY;
}
htlc->rhash = *payment_hash;
if (blinding)
htlc->blinding = tal_dup(htlc, struct pubkey, blinding);
else
htlc->blinding = NULL;
htlc->failed = NULL;
htlc->r = NULL;
htlc->routing = tal_dup_arr(htlc, u8, routing, TOTAL_PACKET_SIZE(ROUTING_INFO_SIZE), 0);
old = htlc_get(channel->htlcs, htlc->id, htlc_owner(htlc));
if (old) {
if (old->state != htlc->state