libplugin: handle JSON reply after command freed.

This can happen, and in fact does below in our test_autoclean_once
test where we update the datastore, and return from the cmd.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2022-09-19 10:19:52 +09:30 committed by Christian Decker
parent 4693803c35
commit 41a52929f7

View file

@ -681,10 +681,13 @@ static void handle_rpc_reply(struct plugin *plugin, const jsmntok_t *toks)
out = strmap_getn(&plugin->out_reqs,
plugin->rpc_buffer + idtok->start,
idtok->end - idtok->start);
if (!out)
plugin_err(plugin, "JSON reply with unknown id '%.*s'",
if (!out) {
/* This can actually happen, if they free req! */
plugin_log(plugin, LOG_DBG, "JSON reply with unknown id '%.*s'",
json_tok_full_len(toks),
json_tok_full(plugin->rpc_buffer, toks));
return;
}
/* Remove destructor if one existed */
if (out->cmd)