mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-15 20:09:18 +01:00
libplugin: fix leak of struct command when we don't read it all at once.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> Changelog-Fixed: Plugins: C plugins would could leak memory on every command (esp. seen when hammering topology's listchannels).
This commit is contained in:
parent
127539a993
commit
4f4c49c88a
1 changed files with 3 additions and 3 deletions
|
@ -1218,10 +1218,10 @@ void plugin_set_memleak_handler(struct plugin *plugin,
|
|||
#endif /* DEVELOPER */
|
||||
|
||||
static void ld_command_handle(struct plugin *plugin,
|
||||
struct command *cmd,
|
||||
const jsmntok_t *toks)
|
||||
{
|
||||
const jsmntok_t *idtok, *methtok, *paramstok;
|
||||
struct command *cmd;
|
||||
|
||||
idtok = json_get_member(plugin->buffer, toks, "id");
|
||||
methtok = json_get_member(plugin->buffer, toks, "method");
|
||||
|
@ -1233,6 +1233,7 @@ static void ld_command_handle(struct plugin *plugin,
|
|||
json_tok_full_len(toks),
|
||||
json_tok_full(plugin->buffer, toks));
|
||||
|
||||
cmd = tal(plugin, struct command);
|
||||
cmd->plugin = plugin;
|
||||
cmd->id = NULL;
|
||||
cmd->usage_only = false;
|
||||
|
@ -1321,7 +1322,6 @@ static void ld_command_handle(struct plugin *plugin,
|
|||
static bool ld_read_json_one(struct plugin *plugin)
|
||||
{
|
||||
bool complete;
|
||||
struct command *cmd = tal(plugin, struct command);
|
||||
|
||||
if (!json_parse_input(&plugin->parser, &plugin->toks,
|
||||
plugin->buffer, plugin->used,
|
||||
|
@ -1346,7 +1346,7 @@ static bool ld_read_json_one(struct plugin *plugin)
|
|||
|
||||
/* FIXME: Spark doesn't create proper jsonrpc 2.0! So we don't
|
||||
* check for "jsonrpc" here. */
|
||||
ld_command_handle(plugin, cmd, plugin->toks);
|
||||
ld_command_handle(plugin, plugin->toks);
|
||||
|
||||
/* Move this object out of the buffer */
|
||||
memmove(plugin->buffer, plugin->buffer + plugin->toks[0].end,
|
||||
|
|
Loading…
Add table
Reference in a new issue