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

@@ -105,10 +105,21 @@ void clean_tmpctx(void);
/* Call this before any libwally function which allocates. */
void tal_wally_start(void);
/* Then call this to reparent everything onto this parent (which must
* have been tal_steal() if it was allocated by libwally here) */
/* Then call this to reparent everything onto this parent */
void tal_wally_end(const tal_t *parent);
/* ... or this if you want to reparent onto something which is
* allocated by libwally here. Fixes up this from_wally obj to have a
* proper tal_name, too! */
#define tal_wally_end_onto(parent, from_wally, type) \
tal_wally_end_onto_((parent), \
(from_wally) + 0*sizeof((from_wally) == (type *)0), \
stringify(type))
void tal_wally_end_onto_(const tal_t *parent,
tal_t *from_wally,
const char *from_wally_name);
/* Define sha256_eq. */
STRUCTEQ_DEF(sha256, 0, u);