mirror of
https://github.com/aljazceru/lightning.git
synced 2026-02-23 06:54:30 +01:00
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>
This commit is contained in:
committed by
Rusty Russell
parent
3564263e12
commit
eac770760c
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user