From 68470c8f221db5e20aec8e71f9cd3ef011d34fd4 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Tue, 7 Sep 2021 13:36:06 +0930 Subject: [PATCH] plugins/txprepare: annotate unreleased_txs list against false memleaks. And fix utx leak in the withdraw case. Signed-off-by: Rusty Russell --- plugins/txprepare.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/plugins/txprepare.c b/plugins/txprepare.c index 84da4161a..b20f2c934 100644 --- a/plugins/txprepare.c +++ b/plugins/txprepare.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -212,6 +213,8 @@ static struct command_result *finish_txprepare(struct command *cmd, if (txp->is_withdraw) { struct out_req *req; + /* Won't live beyond this cmd. */ + tal_steal(cmd, utx); req = jsonrpc_request_start(cmd->plugin, cmd, "signpsbt", signpsbt_done, forward_error, utx); @@ -558,9 +561,25 @@ static const struct plugin_command commands[] = { }, }; +#if DEVELOPER +static void mark_unreleased_txs(struct plugin *plugin, struct htable *memtable) +{ + memleak_remove_region(memtable, &unreleased_txs, sizeof(unreleased_txs)); +} +#endif + +static const char *init(struct plugin *p, + const char *buf UNUSED, const jsmntok_t *config UNUSED) +{ +#if DEVELOPER + plugin_set_memleak_handler(p, mark_unreleased_txs); +#endif + return NULL; +} + int main(int argc, char *argv[]) { setup_locale(); - plugin_main(argv, NULL, PLUGIN_RESTARTABLE, true, NULL, commands, + plugin_main(argv, init, PLUGIN_RESTARTABLE, true, NULL, commands, ARRAY_SIZE(commands), NULL, 0, NULL, 0, NULL, 0, NULL); }