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>
This commit is contained in:
Rusty Russell 2017-12-15 20:50:54 +10:30 committed by Christian Decker
parent 19b1b35d31
commit 70d01b22e1
3 changed files with 12 additions and 8 deletions

View File

@ -41,7 +41,7 @@ static bool pointer_referenced(struct htable *memtable, const void *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)
{
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)) {
const char *name = tal_name(i);
if (p == exclude)
if (p == exclude1 || p == exclude2)
continue;
if (name) {
@ -63,17 +63,19 @@ static void children_into_htable(const void *exclude,
continue;
}
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);
htable_init(memtable, hash_ptr, NULL);
/* 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);
return memtable;

View File

@ -26,7 +26,9 @@ void memleak_init(const tal_t *root, struct backtrace_state *bstate);
void memleak_cleanup(void);
/* 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 */
void memleak_remove_referenced(struct htable *memtable, const void *root);

View File

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