From b3338a174e3a825d480fda669b449b39a8b325ce Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Sat, 26 Feb 2022 11:20:33 +1030 Subject: [PATCH] plugins/keysend: prevent leak detecting getting upset. 1. We don't keep a pointer to payments (unlike pay, which keeps a linked list), so mark it notleak. 2. plugin->our_features is overloaded for "features we want to set" (used by keysend) and then "features we have". Create a new field, which is cleaner. Signed-off-by: Rusty Russell --- plugins/keysend.c | 3 ++- plugins/libplugin.c | 8 +++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/plugins/keysend.c b/plugins/keysend.c index 4c762c3db..6fe37e76f 100644 --- a/plugins/keysend.c +++ b/plugins/keysend.c @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -223,7 +224,7 @@ static struct command_result *json_keysend(struct command *cmd, const char *buf, p->label = tal_steal(p, label); payment_start(p); /* We're keeping this around now */ - tal_steal(cmd->plugin, p); + tal_steal(cmd->plugin, notleak(p)); return command_still_pending(cmd); } diff --git a/plugins/libplugin.c b/plugins/libplugin.c index e77fecb7b..b44114618 100644 --- a/plugins/libplugin.c +++ b/plugins/libplugin.c @@ -87,6 +87,8 @@ struct plugin { /* Feature set for lightningd */ struct feature_set *our_features; + /* Features we want to add to lightningd */ + const struct feature_set *desired_features; /* Location of the RPC filename in case we need to defer RPC * initialization or need to recover from a disconnect. */ @@ -663,10 +665,10 @@ handle_getmanifest(struct command *getmanifest_cmd, } json_array_end(params); - if (p->our_features != NULL) { + if (p->desired_features != NULL) { json_object_start(params, "featurebits"); for (size_t i = 0; i < NUM_FEATURE_PLACE; i++) { - u8 *f = p->our_features->bits[i]; + u8 *f = p->desired_features->bits[i]; const char *fieldname = feature_place_names[i]; if (fieldname == NULL) continue; @@ -1464,7 +1466,7 @@ static struct plugin *new_plugin(const tal_t *ctx, p->next_outreq_id = 0; uintmap_init(&p->out_reqs); - p->our_features = tal_steal(p, features); + p->desired_features = tal_steal(p, features); if (init_rpc) { /* Sync RPC FIXME: maybe go full async ? */ p->rpc_conn = tal(p, struct rpc_conn);