Browse Source

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>
ppa-0.6.1
Rusty Russell 7 years ago
parent
commit
4bdacea7b5
  1. 12
      common/utils.c
  2. 2
      common/utils.h

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

2
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. */

Loading…
Cancel
Save