Skip to content

Commit

Permalink
plugins: Add a destructor to the plugin request, in case it dies
Browse files Browse the repository at this point in the history
Authored-by: @rustyrussell
  • Loading branch information
darosior committed Sep 26, 2019
1 parent ba61ed7 commit bb8f41a
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lightningd/plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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 */
Expand Down

0 comments on commit bb8f41a

Please sign in to comment.