mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 23:24:27 +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:
@@ -34,8 +34,6 @@ void setup_locale(void)
|
|||||||
putenv("LC_ALL=C"); /* For exec{l,lp,v,vp}(...) */
|
putenv("LC_ALL=C"); /* For exec{l,lp,v,vp}(...) */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Global temporary convenience context: freed in io loop core. */
|
|
||||||
|
|
||||||
/* Initial creation of tmpctx. */
|
/* Initial creation of tmpctx. */
|
||||||
void setup_tmpctx(void)
|
void setup_tmpctx(void)
|
||||||
{
|
{
|
||||||
@@ -45,9 +43,9 @@ void setup_tmpctx(void)
|
|||||||
/* Free any children of tmpctx. */
|
/* Free any children of tmpctx. */
|
||||||
void clean_tmpctx(void)
|
void clean_tmpctx(void)
|
||||||
{
|
{
|
||||||
/* Minor optimization: don't do anything if tmpctx unused. */
|
const tal_t *p;
|
||||||
if (tal_first(tmpctx)) {
|
|
||||||
tal_free(tmpctx);
|
/* Don't actually free tmpctx: we hand pointers to it around. */
|
||||||
tmpctx = tal_arr_label(NULL, char, 0, "tmpctx");
|
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. */
|
/* Use the POSIX C locale. */
|
||||||
void setup_locale(void);
|
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;
|
extern const tal_t *tmpctx;
|
||||||
|
|
||||||
/* Initial creation of tmpctx. */
|
/* Initial creation of tmpctx. */
|
||||||
|
|||||||
Reference in New Issue
Block a user