plugins/txprepare: annotate unreleased_txs list against false memleaks.

And fix utx leak in the withdraw case.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2021-09-07 13:36:06 +09:30 committed by Christian Decker
parent 2e0179ffcc
commit 68470c8f22

View file

@ -12,6 +12,7 @@
#include <common/features.h>
#include <common/json_stream.h>
#include <common/json_tok.h>
#include <common/memleak.h>
#include <common/pseudorand.h>
#include <common/type_to_string.h>
#include <common/utils.h>
@ -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);
}