Skip to content

Commit

Permalink
plugin: Avoid calling a destructor on a request that was freed
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cdecker committed Feb 19, 2020
1 parent f063328 commit fe0c052
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lightningd/plugin_hook.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
}
}
Expand Down

0 comments on commit fe0c052

Please sign in to comment.