Browse Source

memleak: don't require a root pointer.

We can just track everything from NULL (the ultimate parent) down.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 6 years ago
committed by Christian Decker
parent
commit
8733015836
  1. 12
      common/memleak.c
  2. 4
      common/memleak.h
  3. 2
      lightningd/lightningd.c

12
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)

4
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);

2
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);

Loading…
Cancel
Save