lightningd: tal memleak detection, dev-memleak command.

This is a primitive mark-and-sweep-style garbage detector.  The core is
in common/ for later use by subdaemons, but for now it's just lightningd.
We initialize it before most other allocations.

We walk the tal tree to get all the pointers, then search the `ld`
object for those pointers, recursing down.  Some specific helpers are
required for hashtables (which stash bits in the unused pointer bits,
so won't be found).

There's `notleak()` for annotating things that aren't leaks: things
like globals and timers, and other semi-transients.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2017-12-15 20:47:54 +10:30
committed by Christian Decker
parent 95df553813
commit c956d9f5eb
14 changed files with 342 additions and 7 deletions

View File

@@ -3,6 +3,7 @@
#include <ccan/tal/str/str.h>
#include <ccan/tal/tal.h>
#include <common/htlc.h>
#include <common/memleak.h>
#include <common/pseudorand.h>
#include <lightningd/htlc_end.h>
#include <lightningd/log.h>
@@ -166,3 +167,31 @@ struct htlc_out *new_htlc_out(const tal_t *ctx,
return htlc_out_check(hout, "new_htlc_out");
}
#if DEVELOPER
void htlc_inmap_mark_pointers_used(struct htable *memtable,
const struct htlc_in_map *map)
{
struct htlc_in *hin;
struct htlc_in_map_iter it;
/* memleak can't see inside hash tables, so do them manually */
for (hin = htlc_in_map_first(map, &it);
hin;
hin = htlc_in_map_next(map, &it))
memleak_scan_region(memtable, hin);
}
void htlc_outmap_mark_pointers_used(struct htable *memtable,
const struct htlc_out_map *map)
{
struct htlc_out *hout;
struct htlc_out_map_iter it;
/* memleak can't see inside hash tables, so do them manually */
for (hout = htlc_out_map_first(map, &it);
hout;
hout = htlc_out_map_next(map, &it))
memleak_scan_region(memtable, hout);
}
#endif /* DEVELOPER */