From 0987747ded2af086f62de84fef5904831a2ce42d 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 | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lightningd/plugin_hook.c b/lightningd/plugin_hook.c index 5551c742a..7801ca187 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, @@ -200,6 +200,15 @@ 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_steal(r, it); + } + tal_free(r); } }