Browse Source

jsonrpc: Make sure we handle the case where jcon outlives command

So far only happens during normal shutdown, but it may happen in other
cases as well. We simply define a new destructor that unregisters the
`cmd` from the `jcon`.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
ppa-0.6.1
Christian Decker 7 years ago
committed by Rusty Russell
parent
commit
eac770760c
  1. 8
      lightningd/jsonrpc.c

8
lightningd/jsonrpc.c

@ -25,6 +25,7 @@ struct json_output {
const char *json;
};
/* jcon and cmd have separate lifetimes: we detach them on either destruction */
static void destroy_jcon(struct json_connection *jcon)
{
log_debug(jcon->log, "Closing (%s)", strerror(errno));
@ -36,6 +37,12 @@ static void destroy_jcon(struct json_connection *jcon)
tal_free(jcon->log);
}
static void destroy_cmd(struct command *cmd)
{
if (cmd->jcon)
cmd->jcon->current = NULL;
}
static void json_help(struct command *cmd,
const char *buffer, const jsmntok_t *params);
@ -460,6 +467,7 @@ static void parse_request(struct json_connection *jcon, const jsmntok_t tok[])
jcon->current->id = tal_strndup(jcon->current,
json_tok_contents(jcon->buffer, id),
json_tok_len(id));
tal_add_destructor(jcon->current, destroy_cmd);
if (!method || !params) {
command_fail(jcon->current, method ? "No params" : "No method");

Loading…
Cancel
Save