diff --git a/lightningd/log.c b/lightningd/log.c index cc0278fc3..9daf0c3a6 100644 --- a/lightningd/log.c +++ b/lightningd/log.c @@ -108,6 +108,10 @@ struct log_book *new_log_book(const tal_t *ctx, lr->init_time = time_now(); list_head_init(&lr->log); + /* In case ltmp not initialized, do so now. */ + if (!ltmp) + ltmp = tal_tmpctx(lr); + return lr; } @@ -185,6 +189,12 @@ static void add_entry(struct log *log, struct log_entry *l) log_debug(log, "Log pruned %zu entries (mem %zu -> %zu)", deleted, old_mem, log->lr->mem_used); } + + /* Free up temporaries now if any */ + if (tal_first(ltmp)) { + tal_free(ltmp); + ltmp = tal_tmpctx(log->lr); + } } static struct log_entry *new_log_entry(struct log *log, enum log_level level) diff --git a/lightningd/log.h b/lightningd/log.h index 7ddb4d3bb..fe83c3a03 100644 --- a/lightningd/log.h +++ b/lightningd/log.h @@ -129,6 +129,10 @@ void log_dump_to_file(int fd, const struct log_book *lr); void opt_register_logging(struct log *log); void crashlog_activate(struct log *log); +/* Convenience parent for temporary allocations (eg. type_to_string) + * during log calls; freed after every log_*() */ +const tal_t *ltmp; + /* Before the crashlog is activated, just prints to stderr. */ void NORETURN PRINTF_FMT(1,2) fatal(const char *fmt, ...); #endif /* LIGHTNING_LIGHTNINGD_LOG_H */