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 <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2022-02-26 11:20:33 +10:30
parent 6c8ea95f6e
commit b3338a174e
2 changed files with 7 additions and 4 deletions

View File

@ -3,6 +3,7 @@
#include <ccan/asort/asort.h>
#include <ccan/tal/str/str.h>
#include <common/json_tok.h>
#include <common/memleak.h>
#include <common/type_to_string.h>
#include <plugins/libplugin-pay.h>
#include <sodium.h>
@ -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);
}

View File

@ -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);