diff --git a/common/memleak.c b/common/memleak.c index 368360961..f1cba6a29 100644 --- a/common/memleak.c +++ b/common/memleak.c @@ -247,14 +247,22 @@ static void add_backtrace(tal_t *parent UNUSED, enum tal_notify_type type UNNEED tal_add_notifier(child, TAL_NOTIFY_ADD_CHILD, add_backtrace); } -void memleak_init(const tal_t *root) +static void add_backtrace_notifiers(const tal_t *root) +{ + tal_add_notifier(root, TAL_NOTIFY_ADD_CHILD, add_backtrace); + + for (tal_t *i = tal_first(root); i; i = tal_next(i)) + add_backtrace_notifiers(i); +} + +void memleak_init(void) { assert(!notleaks); notleaks = tal_arr(NULL, const void *, 0); notleak_children = tal_arr(notleaks, bool, 0); if (backtrace_state) - tal_add_notifier(root, TAL_NOTIFY_ADD_CHILD, add_backtrace); + add_backtrace_notifiers(NULL); } void memleak_cleanup(void) diff --git a/common/memleak.h b/common/memleak.h index e8787ee1c..cd0e12c4a 100644 --- a/common/memleak.h +++ b/common/memleak.h @@ -22,8 +22,8 @@ void *notleak_(const void *ptr, bool plus_children); struct htable; -/* Initialize memleak detection, with this as the root */ -void memleak_init(const tal_t *root); +/* Initialize memleak detection */ +void memleak_init(void); /* Free memleak detection. */ void memleak_cleanup(void); diff --git a/lightningd/lightningd.c b/lightningd/lightningd.c index 00fabbc22..0c5552ece 100644 --- a/lightningd/lightningd.c +++ b/lightningd/lightningd.c @@ -54,7 +54,7 @@ static struct lightningd *new_lightningd(const tal_t *ctx) ld->dev_allow_localhost = false; if (getenv("LIGHTNINGD_DEV_MEMLEAK")) - memleak_init(ld); + memleak_init(); #endif list_head_init(&ld->peers);