From fe0c052329f2880719f63011c94b365c02848f53 Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Sun, 16 Feb 2020 15:56:27 +0100 Subject: [PATCH] plugin: Avoid calling a destructor on a request that was freed We are attaching the destructor to notify us when the plugin exits, but we also need to clear them once the request is handled correctly, so we don't call the destructor when it exits later. --- lightningd/plugin_hook.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lightningd/plugin_hook.c b/lightningd/plugin_hook.c index efb21208c711..f994dbc49717 100644 --- a/lightningd/plugin_hook.c +++ b/lightningd/plugin_hook.c @@ -155,7 +155,7 @@ static void plugin_hook_callback(const char *buffer, const jsmntok_t *toks, const jsmntok_t *resulttok, *resrestok; struct db *db = r->db; bool more_plugins, cont; - struct plugin_hook_call_link *last; + struct plugin_hook_call_link *last, *it; if (r->ld->state == LD_STATE_SHUTDOWN) { log_debug(r->ld->log, @@ -196,6 +196,14 @@ static void plugin_hook_callback(const char *buffer, const jsmntok_t *toks, db_begin_transaction(db); r->hook->response_cb(r->cb_arg, buffer, resulttok); db_commit_transaction(db); + + /* We need to remove the destructors from the remaining + * call-chain, otherwise they'd still be called when the + * plugin dies or we shut down. */ + list_for_each(&r->call_chain, it, list) { + tal_del_destructor(it, plugin_hook_killed); + } + tal_free(r); } }