From d0ccd15ac0006315dd5a7a9f5c4378d326247bd2 Mon Sep 17 00:00:00 2001 From: darosior Date: Thu, 26 Sep 2019 17:00:18 +0200 Subject: [PATCH] plugins: Add a destructor to the plugin request, in case it dies Authored-by: @rustyrussell --- lightningd/plugin.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lightningd/plugin.c b/lightningd/plugin.c index 22103ae21..eba3c1826 100644 --- a/lightningd/plugin.c +++ b/lightningd/plugin.c @@ -252,7 +252,6 @@ static void plugin_response_handle(struct plugin *plugin, /* We expect the request->cb to copy if needed */ request->response_cb(plugin->buffer, toks, idtok, request->response_cb_arg); - uintmap_del(&plugin->plugins->pending_requests, id); tal_free(request); } @@ -1118,12 +1117,20 @@ void plugins_notify(struct plugins *plugins, tal_free(n); } +static void destroy_request(struct jsonrpc_request *req, + struct plugin *plugin) +{ + uintmap_del(&plugin->plugins->pending_requests, req->id); +} + void plugin_request_send(struct plugin *plugin, struct jsonrpc_request *req TAKES) { /* Add to map so we can find it later when routing the response */ tal_steal(plugin, req); uintmap_add(&plugin->plugins->pending_requests, req->id, req); + /* Add destructor in case plugin dies. */ + tal_add_destructor2(req, destroy_request, plugin); plugin_send(plugin, req->stream); /* plugin_send steals the stream, so remove the dangling * pointer here */