Browse Source

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>
ppa-0.6.1
Rusty Russell 8 years ago
parent
commit
3404c393b7
  1. 1
      common/Makefile
  2. 19
      common/io_debug.c
  3. 9
      common/io_debug.h
  4. 8
      common/status.c
  5. 4
      lightningd/log.c

1
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 \

19
common/io_debug.c

@ -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

@ -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 */

8
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. */
if (tal_first(trc)) {
tal_free(trc);
trc = tal_tmpctx(NULL);
trc = tal(NULL, char);
}
}
void status_failed(enum status_fail code, const char *fmt, ...)

4
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);
}
}

Loading…
Cancel
Save