mirror of
https://github.com/aljazceru/lightning.git
synced 2026-02-06 22:54:21 +01:00
common/io_debug: replacement for ccan/io's poll which does sanity checks.
For now we just check for outstanding take() or tal_tmpctx(). Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -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 \
|
||||
|
||||
19
common/io_debug.c
Normal file
19
common/io_debug.c
Normal file
@@ -0,0 +1,19 @@
|
||||
#include <ccan/err/err.h>
|
||||
#include <ccan/take/take.h>
|
||||
#include <common/io_debug.h>
|
||||
#include <common/utils.h>
|
||||
|
||||
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);
|
||||
}
|
||||
9
common/io_debug.h
Normal file
9
common/io_debug.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#ifndef LIGHTNING_COMMON_IO_DEBUG_H
|
||||
#define LIGHTNING_COMMON_IO_DEBUG_H
|
||||
#include "config.h"
|
||||
#include <poll.h>
|
||||
|
||||
/* 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 */
|
||||
@@ -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, ...)
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user