mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-01 17:47:30 +01:00
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:
parent
2d1190d929
commit
4bdacea7b5
2 changed files with 6 additions and 8 deletions
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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…
Add table
Reference in a new issue