Skip to content

Commit 61ecc40

Browse files
committed
common: remove take() leak if new_initial_channel() fails.
This happens in the fuzzer corpora, but that doesn't check for take() leaks. Our unit tests do: ``` fuzz-initial_channel: outstanding taken(): 0x626c3b3affc8 make: *** [Makefile:823: unittest/tests/fuzz/fuzz-initial_channel] Error 1 ``` This doesn't matter in real life, since we exit the subdaemon if this fails, but it's still a bug. Signed-off-by: Rusty Russell <[email protected]>
1 parent abe09ec commit 61ecc40

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

common/initial_channel.c

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,19 @@ struct channel *new_initial_channel(const tal_t *ctx,
3131
struct channel *channel = tal(ctx, struct channel);
3232
struct amount_msat remote_msatoshi;
3333

34+
/* takes() if necessary */
35+
channel->fee_states = dup_fee_states(channel, fee_states);
36+
37+
/* takes() if necessary */
38+
if (!height_states)
39+
channel->blockheight_states = NULL;
40+
else
41+
channel->blockheight_states
42+
= dup_height_states(channel, height_states);
43+
44+
/* takes() if necessary */
45+
channel->type = tal_dup(channel, struct channel_type, type);
46+
3447
channel->cid = *cid;
3548
channel->funding = *funding;
3649
channel->funding_sats = funding_sats;
@@ -47,16 +60,6 @@ struct channel *new_initial_channel(const tal_t *ctx,
4760
channel->funding_pubkey[REMOTE] = *remote_funding_pubkey;
4861
channel->htlcs = NULL;
4962

50-
/* takes() if necessary */
51-
channel->fee_states = dup_fee_states(channel, fee_states);
52-
53-
/* takes() if necessary */
54-
if (!height_states)
55-
channel->blockheight_states = NULL;
56-
else
57-
channel->blockheight_states
58-
= dup_height_states(channel, height_states);
59-
6063
channel->view[LOCAL].owed[LOCAL]
6164
= channel->view[REMOTE].owed[LOCAL]
6265
= local_msatoshi;
@@ -77,8 +80,6 @@ struct channel *new_initial_channel(const tal_t *ctx,
7780
&channel->basepoints[!opener].payment);
7881

7982
channel->option_wumbo = option_wumbo;
80-
/* takes() if necessary */
81-
channel->type = tal_dup(channel, struct channel_type, type);
8283

8384
return channel;
8485
}

0 commit comments

Comments
 (0)