From 246b724dbeb4782f75cf5f51b9eee335192975d6 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Sat, 26 Feb 2022 11:20:33 +1030 Subject: [PATCH] libplugin-pay: fix spurious leak reports. 1. The dijkstra can be temporary, doesn't need to last as long as pay cmd. 2. We fail multiple times in several places, so don't leak old failreason. 3. Make payments findable by our memleak detector. Signed-off-by: Rusty Russell --- plugins/libplugin-pay.c | 6 +++++- plugins/libplugin-pay.h | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/plugins/libplugin-pay.c b/plugins/libplugin-pay.c index ae82c1497..9595dc609 100644 --- a/plugins/libplugin-pay.c +++ b/plugins/libplugin-pay.c @@ -766,7 +766,7 @@ static struct route_hop *route(const tal_t *ctx, /* Try using disabled channels too */ /* FIXME: is there somewhere we can annotate this for paystatus? */ can_carry = payment_route_can_carry_even_disabled; - dij = dijkstra(ctx, gossmap, dst, amount, riskfactor, + dij = dijkstra(tmpctx, gossmap, dst, amount, riskfactor, can_carry, route_score, p); r = route_from_dijkstra(ctx, gossmap, dij, src, amount, final_delay); @@ -2122,6 +2122,8 @@ void payment_abort(struct payment *p, const char *fmt, ...) { payment_set_step(p, PAYMENT_STEP_FAILED); p->end_time = time_now(); + /* We can fail twice, it seems. */ + tal_free(p->failreason); va_start(ap, fmt); p->failreason = tal_vfmt(p, fmt, ap); va_end(ap); @@ -2147,6 +2149,8 @@ void payment_fail(struct payment *p, const char *fmt, ...) va_list ap; p->end_time = time_now(); payment_set_step(p, PAYMENT_STEP_FAILED); + /* We can fail twice, it seems. */ + tal_free(p->failreason); va_start(ap, fmt); p->failreason = tal_vfmt(p, fmt, ap); va_end(ap); diff --git a/plugins/libplugin-pay.h b/plugins/libplugin-pay.h index b2b4ce7fe..4f045e252 100644 --- a/plugins/libplugin-pay.h +++ b/plugins/libplugin-pay.h @@ -160,11 +160,12 @@ struct payment_constraints { }; struct payment { + /* Usually in global payments list */ + struct list_node list; /* The command that triggered this payment. Only set for the root * payment. */ struct command *cmd; struct plugin *plugin; - struct list_node list; struct node_id *local_id; const char *json_buffer;