diff --git a/common/configdir.c b/common/configdir.c index b4e401a11..8bbf29b4c 100644 --- a/common/configdir.c +++ b/common/configdir.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -35,8 +36,7 @@ static char *opt_set_abspath(const char *arg, char **p) /* Tal wrappers for opt. */ static void *opt_allocfn(size_t size) { - return tal_arr_label(NULL, char, size, - TAL_LABEL(opt_allocfn_notleak, "")); + return notleak(tal_arr(NULL, char, size)); } static void *tal_reallocfn(void *ptr, size_t size) diff --git a/common/memleak.c b/common/memleak.c index 7ac0da7c7..de321a9a7 100644 --- a/common/memleak.c +++ b/common/memleak.c @@ -58,9 +58,6 @@ struct tal_backtrace { void *notleak_(void *ptr, bool plus_children) { const char *name; - /* If we're not tracking, don't do anything. */ - if (!memleak_track) - return cast_const(void *, ptr); /* We use special tal names to mark notleak */ name = tal_name(ptr); @@ -69,12 +66,14 @@ void *notleak_(void *ptr, bool plus_children) /* Don't mark more than once! */ if (!strstr(name, "**NOTLEAK")) { + /* Don't use tmpctx: it might not be set up yet! */ if (plus_children) - name = tal_fmt(tmpctx, "%s **NOTLEAK_IGNORE_CHILDREN**", + name = tal_fmt(NULL, "%s **NOTLEAK_IGNORE_CHILDREN**", name); else - name = tal_fmt(tmpctx, "%s **NOTLEAK**", name); + name = tal_fmt(NULL, "%s **NOTLEAK**", name); tal_set_name(ptr, name); + tal_free(name); } return cast_const(void *, ptr); @@ -331,8 +330,7 @@ static void call_memleak_helpers(struct htable *memtable, const tal_t *p) if (strends(name, "struct memleak_helper")) { const struct memleak_helper *mh = i; mh->cb(memtable, p); - } else if (strends(name, " **NOTLEAK**") - || strends(name, "_notleak")) { + } else if (strends(name, " **NOTLEAK**")) { memleak_ptr(memtable, i); memleak_scan_obj(memtable, i); } else if (strends(name, diff --git a/common/trace.c b/common/trace.c index 7ffe7eac1..e3018a00e 100644 --- a/common/trace.c +++ b/common/trace.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -181,15 +182,11 @@ static inline void trace_check_tree(void) {} static void trace_init(void) { const char *dev_trace_file; - const char notleak_name[] = "struct span **NOTLEAK**"; if (active_spans) return; - active_spans = tal_arrz(NULL, struct span, 1); - /* We're usually too early for memleak to be initialized, so mark - * this notleak manually! */ - tal_set_name(active_spans, notleak_name); + active_spans = notleak(tal_arrz(NULL, struct span, 1)); current = NULL; dev_trace_file = getenv("CLN_DEV_TRACE_FILE");