diff --git a/common/Makefile b/common/Makefile index 7e7464876..e5076217e 100644 --- a/common/Makefile +++ b/common/Makefile @@ -15,6 +15,7 @@ COMMON_SRC := \ common/htlc_wire.c \ common/initial_channel.c \ common/initial_commit_tx.c \ + common/io_debug.c \ common/json.c \ common/key_derive.c \ common/keyset.c \ diff --git a/common/io_debug.c b/common/io_debug.c new file mode 100644 index 000000000..738909223 --- /dev/null +++ b/common/io_debug.c @@ -0,0 +1,19 @@ +#include +#include +#include +#include + +int debug_poll(struct pollfd *fds, nfds_t nfds, int timeout) +{ + const char *t; + + t = taken_any(); + if (t) + errx(1, "Outstanding taken pointers: %s", t); + + t = tmpctx_any(); + if (t) + errx(1, "Outstanding tmpctx: %s", t); + + return poll(fds, nfds, timeout); +} diff --git a/common/io_debug.h b/common/io_debug.h new file mode 100644 index 000000000..ae1c73676 --- /dev/null +++ b/common/io_debug.h @@ -0,0 +1,9 @@ +#ifndef LIGHTNING_COMMON_IO_DEBUG_H +#define LIGHTNING_COMMON_IO_DEBUG_H +#include "config.h" +#include + +/* Replacement poll which checks for memory leaks in middle of ccan/io loop. */ +int debug_poll(struct pollfd *fds, nfds_t nfds, int timeout); + +#endif /* LIGHTNING_COMMON_IO_DEBUG_H */ diff --git a/common/status.c b/common/status.c index 9f1ab6df4..eeacf68ff 100644 --- a/common/status.c +++ b/common/status.c @@ -31,7 +31,9 @@ void status_setup_async(struct daemon_conn *master) assert(status_fd == -1); assert(!status_conn); status_conn = master; - trc = tal_tmpctx(NULL); + + /* Don't use tmpctx here, otherwise debug_poll gets upset. */ + trc = tal(NULL, char); } static bool too_large(size_t len, int type) @@ -85,8 +87,10 @@ void status_trace(const char *fmt, ...) va_end(ap); /* Free up any temporary children. */ - tal_free(trc); - trc = tal_tmpctx(NULL); + if (tal_first(trc)) { + tal_free(trc); + trc = tal(NULL, char); + } } void status_failed(enum status_fail code, const char *fmt, ...) diff --git a/lightningd/log.c b/lightningd/log.c index 0b42ed3fc..83fd883a8 100644 --- a/lightningd/log.c +++ b/lightningd/log.c @@ -113,7 +113,7 @@ struct log_book *new_log_book(const tal_t *ctx, /* In case ltmp not initialized, do so now. */ if (!ltmp) - ltmp = tal_tmpctx(lr); + ltmp = tal(lr, char); return lr; } @@ -196,7 +196,7 @@ static void add_entry(struct log *log, struct log_entry *l) /* Free up temporaries now if any */ if (tal_first(ltmp)) { tal_free(ltmp); - ltmp = tal_tmpctx(log->lr); + ltmp = tal(log->lr, char); } }