From ca2f72fd5f643ed2ad08c8799848105232d70b90 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Tue, 30 Jan 2018 16:59:02 +1030 Subject: [PATCH] log: block reporting on minor memleak. Exception: Node /tmp/lightning-t5gxc6gs/test_closing_different_fees/lightning-2/ has memory leaks: [{'value': '0x55caa0a0b8d0', 'label': 'ccan/ccan/tal/str/str.c:90:char[]', 'backtrace': ['ccan/ccan/tal/tal.c:467 (tal_alloc_)', 'ccan/ccan/tal/tal.c:496 (tal_alloc_arr_)', 'ccan/ccan/tal/str/str.c:90 (tal_vfmt)', 'lightningd/log.c:131 (new_log)', 'lightningd/subd.c:632 (new_subd)', 'lightningd/subd.c:686 (new_peer_subd)', 'lightningd/peer_control.c:2487 (peer_accept_channel)', 'lightningd/peer_control.c:674 (peer_sent_nongossip)', 'lightningd/gossip_control.c:55 (peer_nongossip)', 'lightningd/gossip_control.c:142 (gossip_msg)', 'lightningd/subd.c:477 (sd_msg_read)', 'lightningd/subd.c:319 (read_fds)', 'ccan/ccan/io/io.c:59 (next_plan)', 'ccan/ccan/io/io.c:387 (do_plan)', 'ccan/ccan/io/io.c:397 (io_ready)', 'ccan/ccan/io/poll.c:305 (io_loop)', 'lightningd/lightningd.c:347 (main)', '(null):0 ((null))', '(null):0 ((null))', '(null):0 ((null))'], 'parents': ['lightningd/log.c:103:struct log_book', 'lightningd/lightningd.c:43:struct lightningd']}] Technically, true, but we save more memory by sharing the prefix pointer than we lose by leaking it. However, we'd ideally refcount so it's freed if the log is freed and all the entries using it are pruned from the log book. Signed-off-by: Rusty Russell --- lightningd/log.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lightningd/log.c b/lightningd/log.c index 6b731ad41..ad288c21b 100644 --- a/lightningd/log.c +++ b/lightningd/log.c @@ -128,7 +128,8 @@ new_log(const tal_t *ctx, struct log_book *record, const char *fmt, ...) log->lr = record; va_start(ap, fmt); /* log->lr owns this, since its entries keep a pointer to it. */ - log->prefix = tal_vfmt(log->lr, fmt, ap); + /* FIXME: Refcount this! */ + log->prefix = notleak(tal_vfmt(log->lr, fmt, ap)); va_end(ap); return log;