diff --git a/common/utils.c b/common/utils.c index 3634f2484..f6d28c8b7 100644 --- a/common/utils.c +++ b/common/utils.c @@ -34,8 +34,6 @@ void setup_locale(void) putenv("LC_ALL=C"); /* For exec{l,lp,v,vp}(...) */ } -/* Global temporary convenience context: freed in io loop core. */ - /* Initial creation of tmpctx. */ void setup_tmpctx(void) { @@ -45,9 +43,9 @@ void setup_tmpctx(void) /* Free any children of tmpctx. */ void clean_tmpctx(void) { - /* Minor optimization: don't do anything if tmpctx unused. */ - if (tal_first(tmpctx)) { - tal_free(tmpctx); - tmpctx = tal_arr_label(NULL, char, 0, "tmpctx"); - } + const tal_t *p; + + /* Don't actually free tmpctx: we hand pointers to it around. */ + while ((p = tal_first(tmpctx)) != NULL) + tal_free(p); } diff --git a/common/utils.h b/common/utils.h index 9cb2db9c8..d6919fa9b 100644 --- a/common/utils.h +++ b/common/utils.h @@ -22,7 +22,7 @@ u8 *tal_hexdata(const tal_t *ctx, const void *str, size_t len); /* Use the POSIX C locale. */ void setup_locale(void); -/* Global temporary convenience context: freed in io loop core. */ +/* Global temporary convenience context: children freed in io loop core. */ extern const tal_t *tmpctx; /* Initial creation of tmpctx. */