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

@@ -34,20 +34,29 @@ void tal_wally_end(const tal_t *parent)
{
tal_t *p;
while ((p = tal_first(wally_tal_ctx)) != NULL) {
if (p != parent) {
/* Refuse to make a loop! */
assert(p != parent);
#if DEVELOPER
/* Don't steal backtrace from wally_tal_ctx! */
if (tal_name(p) && streq(tal_name(p), "backtrace")) {
tal_free(p);
continue;
}
#endif /* DEVELOPER */
tal_steal(parent, p);
/* Don't steal backtrace from wally_tal_ctx! */
if (tal_name(p) && streq(tal_name(p), "backtrace")) {
tal_free(p);
continue;
}
#endif /* DEVELOPER */
tal_steal(parent, p);
}
wally_tal_ctx = tal_free(wally_tal_ctx);
}
void tal_wally_end_onto_(const tal_t *parent,
tal_t *from_wally,
const char *from_wally_name)
{
if (from_wally)
tal_set_name_(from_wally, from_wally_name, 1);
tal_wally_end(tal_steal(parent, from_wally));
}
#if DEVELOPER
/* If you've got a softref, we assume no reallocs. */
static void dont_move_softref(tal_t *ctx, enum tal_notify_type ntype, void *info)