Browse Source

memleak: add second exclude arg to exclude current commands' jcon.

This is not a child of cmd, since they have independent lifetimes, but
we don't want to noleak them all, since it's only the one currently in
progress (and its children) that we want to exclude.

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

12
common/memleak.c

@ -41,7 +41,7 @@ static bool pointer_referenced(struct htable *memtable, const void *p)
return htable_del(memtable, hash_ptr(p, NULL), p); return htable_del(memtable, hash_ptr(p, NULL), p);
} }
static void children_into_htable(const void *exclude, static void children_into_htable(const void *exclude1, const void *exclude2,
struct htable *memtable, const tal_t *p) struct htable *memtable, const tal_t *p)
{ {
const tal_t *i; const tal_t *i;
@ -49,7 +49,7 @@ static void children_into_htable(const void *exclude,
for (i = tal_first(p); i; i = tal_next(i)) { for (i = tal_first(p); i; i = tal_next(i)) {
const char *name = tal_name(i); const char *name = tal_name(i);
if (p == exclude) if (p == exclude1 || p == exclude2)
continue; continue;
if (name) { if (name) {
@ -63,17 +63,19 @@ static void children_into_htable(const void *exclude,
continue; continue;
} }
htable_add(memtable, hash_ptr(i, NULL), i); htable_add(memtable, hash_ptr(i, NULL), i);
children_into_htable(exclude, memtable, i); children_into_htable(exclude1, exclude2, memtable, i);
} }
} }
struct htable *memleak_enter_allocations(const tal_t *ctx, const void *exclude) struct htable *memleak_enter_allocations(const tal_t *ctx,
const void *exclude1,
const void *exclude2)
{ {
struct htable *memtable = tal(ctx, struct htable); struct htable *memtable = tal(ctx, struct htable);
htable_init(memtable, hash_ptr, NULL); htable_init(memtable, hash_ptr, NULL);
/* First, add all pointers off NULL to table. */ /* First, add all pointers off NULL to table. */
children_into_htable(exclude, memtable, NULL); children_into_htable(exclude1, exclude2, memtable, NULL);
tal_add_destructor(memtable, htable_clear); tal_add_destructor(memtable, htable_clear);
return memtable; return memtable;

4
common/memleak.h

@ -26,7 +26,9 @@ void memleak_init(const tal_t *root, struct backtrace_state *bstate);
void memleak_cleanup(void); void memleak_cleanup(void);
/* Allocate a htable with all the memory we've allocated. */ /* Allocate a htable with all the memory we've allocated. */
struct htable *memleak_enter_allocations(const tal_t *ctx, const void *exclude); struct htable *memleak_enter_allocations(const tal_t *ctx,
const void *exclude1,
const void *exclude2);
/* Remove any pointers to memory under root */ /* Remove any pointers to memory under root */
void memleak_remove_referenced(struct htable *memtable, const void *root); void memleak_remove_referenced(struct htable *memtable, const void *root);

4
lightningd/memdump.c

@ -106,8 +106,8 @@ static void scan_mem(struct command *cmd,
const tal_t *i; const tal_t *i;
const uintptr_t *backtrace; const uintptr_t *backtrace;
/* Enter everything, except this cmd. */ /* Enter everything, except this cmd and its jcon */
memtable = memleak_enter_allocations(cmd, cmd); memtable = memleak_enter_allocations(cmd, cmd, cmd->jcon);
/* First delete known false positives. */ /* First delete known false positives. */
chaintopology_mark_pointers_used(memtable, ld->topology); chaintopology_mark_pointers_used(memtable, ld->topology);

Loading…
Cancel
Save