mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-21 14:24:09 +01:00
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:
parent
19b1b35d31
commit
70d01b22e1
3 changed files with 12 additions and 8 deletions
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Reference in a new issue