tal_tmpctx: keep information around so we can find leaks.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2017-09-28 13:10:57 +09:30
parent 7200002773
commit e587ec3bd3
2 changed files with 40 additions and 2 deletions

View File

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