From ae956f2a7bbfada36a456c8ccdf63ff28c67c8cd Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Mon, 11 May 2026 17:14:00 +0930 Subject: [PATCH] xpay: fix taken leak if we fail xpay_core early. This was uncovered by a test in the next commit. Signed-off-by: Rusty Russell --- plugins/xpay/xpay.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/plugins/xpay/xpay.c b/plugins/xpay/xpay.c index ca5c0a95c..ebf0bf574 100644 --- a/plugins/xpay/xpay.c +++ b/plugins/xpay/xpay.c @@ -2530,6 +2530,10 @@ static struct command_result *xpay_core(struct command *cmd, struct out_req *req; const char *err; + /* Make our own copy here, in case we exit early. */ + if (!taken(invstring)) + invstring = tal_strdup(tmpctx, invstring); + if (bolt12_has_prefix(invstring)) { struct tlv_invoice *b12inv = invoice_decode(tmpctx, invstring, @@ -2555,7 +2559,7 @@ static struct command_result *xpay_core(struct command *cmd, retryfor, maxdelay, layers, - invstring, + take(invstring), b12inv->invoice_node_id, b12inv->invoice_payment_hash, amount_msat(*b12inv->invoice_amount), @@ -2651,7 +2655,7 @@ static struct command_result *xpay_core(struct command *cmd, retryfor, maxdelay, layers, - invstring, + take(invstring), &dst, &b11->payment_hash, *msat,