Skip to content

Commit 5e4eb7b

Browse files
Lagrang3ShahanaFarooqui
authored andcommitted
renepay: fix double free of tal object
routefail object allocation was linked to route, we had a crash of the plugin with the following error: 0x561f424fc07a send_backtrace common/daemon.c:33 0x561f424fc102 crashdump common/daemon.c:75 0x7f5b0e7dc04f ??? ???:0 0x7f5b0e82ae2c ??? ???:0 0x7f5b0e7dbfb1 ??? ???:0 0x7f5b0e7c6471 ??? ???:0 0x561f4252581f call_error ccan/ccan/tal/tal.c:95 0x561f425258c8 check_bounds ccan/ccan/tal/tal.c:169 0x561f425258f9 to_tal_hdr ccan/ccan/tal/tal.c:179 0x561f42526283 tal_free ccan/ccan/tal/tal.c:525 0x561f424e5379 routefail_end plugins/renepay/routefail.c:52 0x561f424e557b handle_failure plugins/renepay/routefail.c:431 apparently there was a race condition for which the route was first freed before we arrived to routefail_end where we manually free routefail. I don't see how this could have happened, but anyways this subtle bug can be avoided by linking the routefail to the payment. Signed-off-by: Lagrang3 <[email protected]>
1 parent c4d0447 commit 5e4eb7b

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

plugins/renepay/routefail.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,14 @@ struct command_result *routefail_start(const tal_t *ctx, struct route *route,
4343
return update_gossip(r);
4444
}
4545

46-
static struct command_result *routefail_end(struct routefail *r)
46+
static struct command_result *routefail_end(struct routefail *r TAKES)
4747
{
4848
/* Notify the tracker that route has failed and routefail have completed
4949
* handling all possible errors cases. */
5050
struct command *cmd = r->cmd;
5151
route_failure_register(r->payment->routetracker, r->route);
52-
tal_free(r);
52+
if (taken(r))
53+
r = tal_steal(tmpctx, r);
5354
return notification_handled(cmd);
5455
}
5556

@@ -428,5 +429,5 @@ static struct command_result *handle_failure(struct routefail *r)
428429

429430
break;
430431
}
431-
return routefail_end(r);
432+
return routefail_end(take(r));
432433
}

plugins/renepay/routetracker.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ struct command_result *notification_sendpay_failure(struct command *cmd,
402402

403403
/* we do some error processing steps before calling
404404
* route_failure_register. */
405-
return routefail_start(route, route, cmd);
405+
return routefail_start(payment, route, cmd);
406406
}
407407

408408
struct command_result *notification_sendpay_success(struct command *cmd,

0 commit comments

Comments
 (0)