From 20769979a9998e15438d1c439dc439551cf1cca1 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Mon, 13 Sep 2021 23:25:09 +0930 Subject: [PATCH] lightningd: fix leak report when close called multiple times. ``` Global errors: - Node /tmp/ltests-odpd7qtt/test_close_twice_1/lightning-1/ has memory leaks: [ { "backtrace": [ "ccan/ccan/tal/tal.c:442 (tal_alloc_)", "ccan/ccan/tal/tal.c:471 (tal_alloc_arr_)", "lightningd/peer_control.c:1673 (param_feerate_range)", "common/param.c:43 (make_callback)", "common/param.c:140 (parse_by_name)", "common/param.c:259 (param_arr)", "common/param.c:344 (param)", "lightningd/peer_control.c:1706 (json_close)", "lightningd/jsonrpc.c:643 (command_exec)", "lightningd/jsonrpc.c:778 (rpc_command_hook_final)", "lightningd/plugin_hook.c:280 (plugin_hook_call_)", "lightningd/jsonrpc.c:866 (plugin_hook_call_rpc_command)", "lightningd/jsonrpc.c:965 (parse_request)", "lightningd/jsonrpc.c:1056 (read_json)", "ccan/ccan/io/io.c:59 (next_plan)", "ccan/ccan/io/io.c:407 (do_plan)", "ccan/ccan/io/io.c:417 (io_ready)", "ccan/ccan/io/poll.c:445 (io_loop)", "lightningd/io_loop_with_timers.c:24 (io_loop_with_timers)", "lightningd/lightningd.c:1123 (main)" ], "label": "lightningd/peer_control.c:1673:u32[]", "parents": [ "lightningd/channel.c:372:struct channel" ], "value": "0x56428b886208" } ] ``` Signed-off-by: Rusty Russell --- lightningd/peer_control.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lightningd/peer_control.c b/lightningd/peer_control.c index fd6e49b25267..39481b031b1a 100644 --- a/lightningd/peer_control.c +++ b/lightningd/peer_control.c @@ -1871,6 +1871,9 @@ static struct command_result *json_close(struct command *cmd, wrong_funding_changed = false; } + /* May already be set by previous close cmd. */ + tal_free(channel->closing_feerate_range); + /* Works fine if feerate_range is NULL */ channel->closing_feerate_range = tal_steal(channel, feerate_range);