memleak: handle libwally allocations better.

Things allocated by libwally all get the tal_name "wally_tal",
which cost me a few hours trying to find a leak.

In the case where we're making one of the allocations the parent
of the others (e.g. a wally_psbt), we can do better: supply a name
for the tal_wally_end().

So I add a new tal_wally_end_onto() which does the standard
tal_steal() trick, and also changes the (typechecked!) name.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2022-03-20 12:59:27 +10:30
parent 8994b8dade
commit 65be18d355
9 changed files with 55 additions and 33 deletions

View File

@@ -1470,7 +1470,9 @@ static void send_funding_tx(struct channel *channel,
wally_tx_clone_alloc(wtx, 0,
cast_const2(struct wally_tx **,
&cs->wtx));
tal_wally_end(tal_steal(cs, cs->wtx));
tal_wally_end_onto(cs,
cast_const(struct wally_tx *,
cs->wtx), struct wally_tx);
}
wally_txid(wtx, &txid);
@@ -2405,7 +2407,7 @@ json_openchannel_signed(struct command *cmd,
/* Make memleak happy, (otherwise cleaned up with `cmd`) */
tal_free(psbt);
tal_wally_end(tal_steal(inflight, inflight->funding_psbt));
tal_wally_end_onto(inflight, inflight->funding_psbt, struct wally_psbt);
/* Update the PSBT on disk */
wallet_inflight_save(cmd->ld->wallet, inflight);