From da1bcc225d46c2c895c891759c298184932c4e6b Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Tue, 14 Jul 2020 14:39:56 +0200 Subject: [PATCH] plugin: Fix a memory leak and a missing dereference in listconfigs `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`. --- lightningd/plugin.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lightningd/plugin.c b/lightningd/plugin.c index 557ba67a5..b21a127f1 100644 --- a/lightningd/plugin.c +++ b/lightningd/plugin.c @@ -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) { @@ -647,7 +649,6 @@ 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; @@ -655,8 +656,10 @@ static const char *plugin_opt_add(struct plugin *plugin, const char *buffer, return tal_fmt(plugin, "Only \"string\", \"int\", \"bool\", and \"flag\" options are supported"); } - if (!defaulttok) + + if (!popt->description) popt->description = json_strdup(popt, buffer, desctok); + list_add_tail(&plugin->plugin_opts, &popt->list); if (streq(popt->type, "flag")) @@ -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) {