pay: close leaks.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2017-12-15 20:59:41 +10:30
committed by Christian Decker
parent 85f065a6e7
commit ba6904f833
3 changed files with 8 additions and 5 deletions

View File

@@ -153,7 +153,7 @@ struct htlc_out *new_htlc_out(const tal_t *ctx,
hout->msatoshi = msatoshi;
hout->cltv_expiry = cltv_expiry;
hout->payment_hash = *payment_hash;
hout->payment = payment;
hout->payment = tal_steal(hout, payment);
memcpy(hout->onion_routing_packet, onion_routing_packet,
sizeof(hout->onion_routing_packet));

View File

@@ -127,7 +127,7 @@ struct htlc_in *new_htlc_in(const tal_t *ctx,
const struct secret *shared_secret,
const u8 *onion_routing_packet);
/* You need to set the ID, then connect_htlc_out this! */
/* You need to set the ID, then connect_htlc_out this! Steals @payment. */
struct htlc_out *new_htlc_out(const tal_t *ctx,
struct peer *peer,
u64 msatoshi, u32 cltv_expiry,

View File

@@ -157,9 +157,11 @@ static bool send_payment(struct command *cmd,
struct onionpacket *packet;
struct secret *path_secrets;
enum onion_type failcode;
/* Freed automatically on cmd completion: only manually at end. */
const tal_t *tmpctx = tal_tmpctx(cmd);
size_t i, n_hops = tal_count(route);
struct hop_data *hop_data = tal_arr(cmd, struct hop_data, n_hops);
struct pubkey *ids = tal_arr(cmd, struct pubkey, n_hops);
struct hop_data *hop_data = tal_arr(tmpctx, struct hop_data, n_hops);
struct pubkey *ids = tal_arr(tmpctx, struct pubkey, n_hops);
struct wallet_payment *payment = NULL;
/* Expiry for HTLCs is absolute. And add one to give some margin. */
@@ -239,7 +241,7 @@ static bool send_payment(struct command *cmd,
list_add_tail(&cmd->ld->pay_commands, &pc->list);
tal_add_destructor(pc, pay_command_destroyed);
payment = tal(pc, struct wallet_payment);
payment = tal(tmpctx, struct wallet_payment);
payment->id = 0;
payment->incoming = false;
payment->payment_hash = *rhash;
@@ -276,6 +278,7 @@ static bool send_payment(struct command *cmd,
onion_type_name(failcode));
return false;
}
tal_free(tmpctx);
return true;
}