common/utils: don't free tmpctx, just the children.

In some daemons I want to hand it into a loop, which would call
clean_tmpctx().  This causes a subtle bug.

So just free the children directly: the pointer itself remains valid.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2018-08-02 16:19:22 +09:30
parent 2d1190d929
commit 4bdacea7b5
2 changed files with 6 additions and 8 deletions

View File

@@ -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);
}