From c5a0d8cfbf40ad8c3167399eb8e726c4e982c751 Mon Sep 17 00:00:00 2001 From: niftynei Date: Thu, 14 May 2020 20:20:56 -0500 Subject: [PATCH] wally: override wally to use tal-context See attached. This lets us do fancy things with tal_steal --- common/daemon.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/common/daemon.c b/common/daemon.c index efc3d2c8c..29059bb59 100644 --- a/common/daemon.c +++ b/common/daemon.c @@ -18,6 +18,8 @@ #include #include +static const tal_t *wally_tal_ctx; + #if BACKTRACE_SUPPORTED static void (*bt_print)(const char *fmt, ...) PRINTF_FMT(1,2); static void (*bt_exit)(void); @@ -119,6 +121,21 @@ static void add_steal_notifiers(const tal_t *root) } #endif +static void *wally_tal(size_t size) +{ + return tal_arr_label(wally_tal_ctx, u8, size, "wally_notleak"); +} + +static void wally_free(void *ptr) +{ + tal_free(ptr); +} + +static struct wally_operations wally_tal_ops = { + .malloc_fn = wally_tal, + .free_fn = wally_free, +}; + void daemon_setup(const char *argv0, void (*backtrace_print)(const char *fmt, ...), void (*backtrace_exit)(void)) @@ -153,7 +170,11 @@ void daemon_setup(const char *argv0, /* We handle write returning errors! */ signal(SIGPIPE, SIG_IGN); + + /* We set up Wally, the bitcoin wallet lib */ + wally_tal_ctx = tal_label(NULL, char, "wally_ctx_notleak"); wally_init(0); + wally_set_operations(&wally_tal_ops); secp256k1_ctx = wally_get_secp_context(); setup_tmpctx(); @@ -164,6 +185,7 @@ void daemon_shutdown(void) { tal_free(tmpctx); wally_cleanup(0); + wally_free(wally_tal_ctx); } void daemon_maybe_debug(char *argv[])