mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-22 14:42:40 +01:00
renepay: fix some memory leaks
This commit is contained in:
parent
7b18056b09
commit
7335777595
6 changed files with 20 additions and 8 deletions
|
@ -29,10 +29,10 @@ struct pay_plugin *pay_plugin;
|
|||
static void memleak_mark(struct plugin *p, struct htable *memtable)
|
||||
{
|
||||
memleak_scan_obj(memtable, pay_plugin);
|
||||
|
||||
// TODO is this necessary?
|
||||
// memleak_scan_htable(memtable, &pay_plugin->chan_extra_map->raw);
|
||||
// memleak_scan_htable(memtable, &pay_plugin->payment_map->raw);
|
||||
memleak_scan_htable(memtable,
|
||||
&pay_plugin->uncertainty->chan_extra_map->raw);
|
||||
memleak_scan_htable(memtable, &pay_plugin->payment_map->raw);
|
||||
memleak_scan_htable(memtable, &pay_plugin->route_map->raw);
|
||||
}
|
||||
|
||||
static const char *init(struct plugin *p,
|
||||
|
|
|
@ -335,6 +335,7 @@ static struct command_result *selfpay_success(struct command *cmd,
|
|||
const jsmntok_t *tok,
|
||||
struct route *route)
|
||||
{
|
||||
tal_steal(tmpctx, route); // discard this route when tmpctx clears
|
||||
struct payment *payment =
|
||||
payment_map_get(pay_plugin->payment_map, route->key.payment_hash);
|
||||
assert(payment);
|
||||
|
@ -357,6 +358,7 @@ static struct command_result *selfpay_failure(struct command *cmd,
|
|||
const jsmntok_t *tok,
|
||||
struct route *route)
|
||||
{
|
||||
tal_steal(tmpctx, route); // discard this route when tmpctx clears
|
||||
struct payment *payment =
|
||||
payment_map_get(pay_plugin->payment_map, route->key.payment_hash);
|
||||
assert(payment);
|
||||
|
@ -382,6 +384,8 @@ static struct command_result *selfpay_cb(struct payment *payment)
|
|||
"Selfpay: cannot get a valid cmd.");
|
||||
|
||||
struct payment_info *pinfo = &payment->payment_info;
|
||||
/* Self-payment routes are not part of the routetracker, we build them
|
||||
* on-the-fly here and release them on success or failure. */
|
||||
struct route *route =
|
||||
new_route(payment, payment->groupid,
|
||||
/*partid=*/0, pinfo->payment_hash,
|
||||
|
@ -748,7 +752,7 @@ compute_routes_done(struct command *cmd UNUSED, const char *buf UNUSED,
|
|||
// in the local gossmap.
|
||||
|
||||
enum jsonrpc_errcode errcode;
|
||||
const char *err_msg;
|
||||
const char *err_msg = NULL;
|
||||
|
||||
gossmap_apply_localmods(pay_plugin->gossmap, payment->local_gossmods);
|
||||
// TODO: add an algorithm selector here
|
||||
|
@ -775,13 +779,17 @@ compute_routes_done(struct command *cmd UNUSED, const char *buf UNUSED,
|
|||
|
||||
&errcode,
|
||||
&err_msg);
|
||||
err_msg = tal_steal(tmpctx, err_msg);
|
||||
|
||||
gossmap_remove_localmods(pay_plugin->gossmap, payment->local_gossmods);
|
||||
|
||||
/* Couldn't feasible route, we stop. */
|
||||
if (!payment->routes_computed) {
|
||||
if(err_msg==NULL)
|
||||
err_msg = tal_fmt(tmpctx, "get_routes returned NULL error message");
|
||||
return payment_fail(payment, errcode, "%s", err_msg);
|
||||
}
|
||||
|
||||
return payment_continue(payment);
|
||||
}
|
||||
|
||||
|
|
|
@ -280,7 +280,10 @@ struct command_result *payment_success(struct payment *payment,
|
|||
assert(preimage);
|
||||
payment->status = PAYMENT_SUCCESS;
|
||||
payment->preimage = tal_free(payment->preimage);
|
||||
payment->preimage = tal_dup(payment, struct preimage, preimage);
|
||||
if(taken(preimage))
|
||||
payment->preimage = tal_steal(payment, preimage);
|
||||
else
|
||||
payment->preimage = tal_dup(payment, struct preimage, preimage);
|
||||
return payment_finish(payment);
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ struct payment {
|
|||
enum payment_status status;
|
||||
|
||||
/* Payment preimage, in case of success. */
|
||||
struct preimage *preimage;
|
||||
const struct preimage *preimage;
|
||||
|
||||
/* Final error code and message, in case of failure. */
|
||||
enum jsonrpc_errcode error_code;
|
||||
|
|
|
@ -238,7 +238,7 @@ void payment_collect_results(struct payment *payment,
|
|||
if (r->result->status == SENDPAY_COMPLETE && payment_preimage) {
|
||||
assert(r->result->payment_preimage);
|
||||
*payment_preimage =
|
||||
tal_dup(payment, struct preimage,
|
||||
tal_dup(tmpctx, struct preimage,
|
||||
r->result->payment_preimage);
|
||||
}
|
||||
|
||||
|
|
|
@ -89,6 +89,7 @@ int uncertainty_update(struct uncertainty *uncertainty, struct gossmap *gossmap)
|
|||
}
|
||||
for(size_t i=0;i<tal_count(del_list);i++) {
|
||||
chan_extra_map_del(chan_extra_map, del_list[i]);
|
||||
del_list[i] = tal_free(del_list[i]);
|
||||
}
|
||||
del_list = tal_free(del_list);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue