mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 21:35:11 +01:00
tal_tmpctx: keep information around so we can find leaks.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
7200002773
commit
e587ec3bd3
@ -1,5 +1,7 @@
|
||||
#include "utils.h"
|
||||
#include <ccan/list/list.h>
|
||||
#include <ccan/str/hex/hex.h>
|
||||
#include <ccan/tal/str/str.h>
|
||||
|
||||
secp256k1_context *secp256k1_ctx;
|
||||
|
||||
@ -22,3 +24,35 @@ u8 *tal_hexdata(const tal_t *ctx, const void *str, size_t len)
|
||||
return NULL;
|
||||
return data;
|
||||
}
|
||||
|
||||
struct tmpctx {
|
||||
struct list_node list;
|
||||
const char *file;
|
||||
unsigned int line;
|
||||
};
|
||||
|
||||
static struct list_head tmpctxs = LIST_HEAD_INIT(tmpctxs);
|
||||
|
||||
static void destroy_tmpctx(struct tmpctx *t)
|
||||
{
|
||||
list_del_from(&tmpctxs, &t->list);
|
||||
}
|
||||
|
||||
tal_t *tal_tmpctx_(const tal_t *ctx, const char *file, unsigned int line)
|
||||
{
|
||||
struct tmpctx *t = tal(ctx, struct tmpctx);
|
||||
t->file = file;
|
||||
t->line = line;
|
||||
list_add_tail(&tmpctxs, &t->list);
|
||||
tal_add_destructor(t, destroy_tmpctx);
|
||||
return t;
|
||||
}
|
||||
|
||||
const char *tmpctx_any(void)
|
||||
{
|
||||
struct tmpctx *t = list_top(&tmpctxs, struct tmpctx, list);
|
||||
|
||||
if (t)
|
||||
return tal_fmt(t, "%s:%u", t->file, t->line);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -16,8 +16,12 @@ char *tal_hex(const tal_t *ctx, const tal_t *data);
|
||||
/* Allocate and fill a buffer with the data of this hex string. */
|
||||
u8 *tal_hexdata(const tal_t *ctx, const void *str, size_t len);
|
||||
|
||||
/* Get a temporary context for this function scope (tal_free at end) */
|
||||
tal_t *tal_tmpctx_(const tal_t *ctx, const char *file, unsigned int line);
|
||||
#define tal_tmpctx(ctx) \
|
||||
tal_alloc_((ctx), 0, false, false, \
|
||||
__FILE__ ":" stringify(__LINE__) ":tal_tmpctx")
|
||||
tal_tmpctx_((ctx), __FILE__, __LINE__)
|
||||
|
||||
/* Return non-NULL if any tmpctx still allocated. */
|
||||
const char *tmpctx_any(void);
|
||||
|
||||
#endif /* LIGHTNING_COMMON_UTILS_H */
|
||||
|
Loading…
Reference in New Issue
Block a user