mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-23 15:00:34 +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)
|
static void memleak_mark(struct plugin *p, struct htable *memtable)
|
||||||
{
|
{
|
||||||
memleak_scan_obj(memtable, pay_plugin);
|
memleak_scan_obj(memtable, pay_plugin);
|
||||||
|
memleak_scan_htable(memtable,
|
||||||
// TODO is this necessary?
|
&pay_plugin->uncertainty->chan_extra_map->raw);
|
||||||
// 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->payment_map->raw);
|
memleak_scan_htable(memtable, &pay_plugin->route_map->raw);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char *init(struct plugin *p,
|
static const char *init(struct plugin *p,
|
||||||
|
|
|
@ -335,6 +335,7 @@ static struct command_result *selfpay_success(struct command *cmd,
|
||||||
const jsmntok_t *tok,
|
const jsmntok_t *tok,
|
||||||
struct route *route)
|
struct route *route)
|
||||||
{
|
{
|
||||||
|
tal_steal(tmpctx, route); // discard this route when tmpctx clears
|
||||||
struct payment *payment =
|
struct payment *payment =
|
||||||
payment_map_get(pay_plugin->payment_map, route->key.payment_hash);
|
payment_map_get(pay_plugin->payment_map, route->key.payment_hash);
|
||||||
assert(payment);
|
assert(payment);
|
||||||
|
@ -357,6 +358,7 @@ static struct command_result *selfpay_failure(struct command *cmd,
|
||||||
const jsmntok_t *tok,
|
const jsmntok_t *tok,
|
||||||
struct route *route)
|
struct route *route)
|
||||||
{
|
{
|
||||||
|
tal_steal(tmpctx, route); // discard this route when tmpctx clears
|
||||||
struct payment *payment =
|
struct payment *payment =
|
||||||
payment_map_get(pay_plugin->payment_map, route->key.payment_hash);
|
payment_map_get(pay_plugin->payment_map, route->key.payment_hash);
|
||||||
assert(payment);
|
assert(payment);
|
||||||
|
@ -382,6 +384,8 @@ static struct command_result *selfpay_cb(struct payment *payment)
|
||||||
"Selfpay: cannot get a valid cmd.");
|
"Selfpay: cannot get a valid cmd.");
|
||||||
|
|
||||||
struct payment_info *pinfo = &payment->payment_info;
|
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 =
|
struct route *route =
|
||||||
new_route(payment, payment->groupid,
|
new_route(payment, payment->groupid,
|
||||||
/*partid=*/0, pinfo->payment_hash,
|
/*partid=*/0, pinfo->payment_hash,
|
||||||
|
@ -748,7 +752,7 @@ compute_routes_done(struct command *cmd UNUSED, const char *buf UNUSED,
|
||||||
// in the local gossmap.
|
// in the local gossmap.
|
||||||
|
|
||||||
enum jsonrpc_errcode errcode;
|
enum jsonrpc_errcode errcode;
|
||||||
const char *err_msg;
|
const char *err_msg = NULL;
|
||||||
|
|
||||||
gossmap_apply_localmods(pay_plugin->gossmap, payment->local_gossmods);
|
gossmap_apply_localmods(pay_plugin->gossmap, payment->local_gossmods);
|
||||||
// TODO: add an algorithm selector here
|
// TODO: add an algorithm selector here
|
||||||
|
@ -775,13 +779,17 @@ compute_routes_done(struct command *cmd UNUSED, const char *buf UNUSED,
|
||||||
|
|
||||||
&errcode,
|
&errcode,
|
||||||
&err_msg);
|
&err_msg);
|
||||||
|
err_msg = tal_steal(tmpctx, err_msg);
|
||||||
|
|
||||||
gossmap_remove_localmods(pay_plugin->gossmap, payment->local_gossmods);
|
gossmap_remove_localmods(pay_plugin->gossmap, payment->local_gossmods);
|
||||||
|
|
||||||
/* Couldn't feasible route, we stop. */
|
/* Couldn't feasible route, we stop. */
|
||||||
if (!payment->routes_computed) {
|
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_fail(payment, errcode, "%s", err_msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
return payment_continue(payment);
|
return payment_continue(payment);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -280,6 +280,9 @@ struct command_result *payment_success(struct payment *payment,
|
||||||
assert(preimage);
|
assert(preimage);
|
||||||
payment->status = PAYMENT_SUCCESS;
|
payment->status = PAYMENT_SUCCESS;
|
||||||
payment->preimage = tal_free(payment->preimage);
|
payment->preimage = tal_free(payment->preimage);
|
||||||
|
if(taken(preimage))
|
||||||
|
payment->preimage = tal_steal(payment, preimage);
|
||||||
|
else
|
||||||
payment->preimage = tal_dup(payment, struct preimage, preimage);
|
payment->preimage = tal_dup(payment, struct preimage, preimage);
|
||||||
return payment_finish(payment);
|
return payment_finish(payment);
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@ struct payment {
|
||||||
enum payment_status status;
|
enum payment_status status;
|
||||||
|
|
||||||
/* Payment preimage, in case of success. */
|
/* Payment preimage, in case of success. */
|
||||||
struct preimage *preimage;
|
const struct preimage *preimage;
|
||||||
|
|
||||||
/* Final error code and message, in case of failure. */
|
/* Final error code and message, in case of failure. */
|
||||||
enum jsonrpc_errcode error_code;
|
enum jsonrpc_errcode error_code;
|
||||||
|
|
|
@ -238,7 +238,7 @@ void payment_collect_results(struct payment *payment,
|
||||||
if (r->result->status == SENDPAY_COMPLETE && payment_preimage) {
|
if (r->result->status == SENDPAY_COMPLETE && payment_preimage) {
|
||||||
assert(r->result->payment_preimage);
|
assert(r->result->payment_preimage);
|
||||||
*payment_preimage =
|
*payment_preimage =
|
||||||
tal_dup(payment, struct preimage,
|
tal_dup(tmpctx, struct preimage,
|
||||||
r->result->payment_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++) {
|
for(size_t i=0;i<tal_count(del_list);i++) {
|
||||||
chan_extra_map_del(chan_extra_map, 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);
|
del_list = tal_free(del_list);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue