mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-02 18:35:00 +01:00
common: add tal_gather_wally() function to reparent libwally objs.
This lets us reduce leaks, and ease their detection. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
3c8049f32c
commit
a316c517c7
3 changed files with 16 additions and 2 deletions
|
@ -5,8 +5,6 @@
|
|||
#include <sodium.h>
|
||||
#include <wally_core.h>
|
||||
|
||||
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");
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include <ccan/tal/str/str.h>
|
||||
#include <locale.h>
|
||||
|
||||
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)
|
||||
|
|
|
@ -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 */
|
||||
|
|
Loading…
Add table
Reference in a new issue