Skip to content

Commit

Permalink
plugin: Fix a memory leak and a missing dereference in listconfigs
Browse files Browse the repository at this point in the history
`listconfigs` calls were setting the description twice and was using the
pointer to the boolean value as the boolean value, resulting in always
returning `true`.
  • Loading branch information
cdecker committed Jul 14, 2020
1 parent 90d1dd6 commit ee8eb0d
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lightningd/plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,8 @@ static const char *plugin_opt_add(struct plugin *plugin, const char *buffer,

popt->name = tal_fmt(popt, "--%.*s", nametok->end - nametok->start,
buffer + nametok->start);
popt->description = NULL;

if (json_tok_streq(buffer, typetok, "string")) {
popt->type = "string";
if (defaulttok) {
Expand Down Expand Up @@ -647,16 +649,17 @@ static const char *plugin_opt_add(struct plugin *plugin, const char *buffer,
} else if (json_tok_streq(buffer, typetok, "flag")) {
popt->type = "flag";
popt->value->as_bool = talz(popt->value, bool);
popt->description = json_strdup(popt, buffer, desctok);
/* We default flags to false, the default token is ignored */
*popt->value->as_bool = false;

} else {
return tal_fmt(plugin,
"Only \"string\", \"int\", \"bool\", and \"flag\" options are supported");
}
if (!defaulttok)

if (!defaulttok && !popt->description)
popt->description = json_strdup(popt, buffer, desctok);

list_add_tail(&plugin->plugin_opts, &popt->list);

if (streq(popt->type, "flag"))
Expand Down Expand Up @@ -1425,7 +1428,7 @@ void json_add_opt_plugins(struct json_stream *response,
/* Trim the `--` that we added before */
opt_name = opt->name + 2;
if (opt->value->as_bool) {
json_add_bool(response, opt_name, opt->value->as_bool);
json_add_bool(response, opt_name, *opt->value->as_bool);
} else if (opt->value->as_int) {
json_add_s64(response, opt_name, *opt->value->as_int);
} else if (opt->value->as_str) {
Expand Down

0 comments on commit ee8eb0d

Please sign in to comment.