diff --git a/common/setup.c b/common/setup.c index fa0462e95..f0d5c0d5f 100644 --- a/common/setup.c +++ b/common/setup.c @@ -5,8 +5,6 @@ #include #include -static const tal_t *wally_tal_ctx; - static void *wally_tal(size_t size) { return tal_arr_label(wally_tal_ctx, u8, size, "wally_notleak"); diff --git a/common/utils.c b/common/utils.c index 37c4457fc..a67321873 100644 --- a/common/utils.c +++ b/common/utils.c @@ -5,6 +5,7 @@ #include #include +const tal_t *wally_tal_ctx; secp256k1_context *secp256k1_ctx; const tal_t *tmpctx; @@ -15,6 +16,15 @@ bool is_elements(const struct chainparams *chainparams) return chainparams->is_elements; } +/* Steal any wally allocations onto this context. */ +void tal_gather_wally(const tal_t *ctx) +{ + tal_t *p; + assert(tal_first(wally_tal_ctx)); + while ((p = tal_first(wally_tal_ctx)) != NULL) + tal_steal(ctx, p); +} + #if DEVELOPER /* If you've got a softref, we assume no reallocs. */ static void dont_move_softref(tal_t *ctx, enum tal_notify_type ntype, void *info) diff --git a/common/utils.h b/common/utils.h index 925228de7..a6b273405 100644 --- a/common/utils.h +++ b/common/utils.h @@ -84,6 +84,9 @@ void setup_tmpctx(void); /* Free any children of tmpctx. */ void clean_tmpctx(void); +/* Steal any wally allocations onto this context. */ +void tal_gather_wally(const tal_t *ctx); + /* Define sha256_eq. */ STRUCTEQ_DEF(sha256, 0, u); @@ -106,4 +109,7 @@ STRUCTEQ_DEF(ripemd160, 0, u); #define IFDEV(dev, nondev) (nondev) #endif +/* Context which all wally allocations use (see common/setup.c) */ +extern const tal_t *wally_tal_ctx; + #endif /* LIGHTNING_COMMON_UTILS_H */