2017-12-15 11:17:54 +01:00
|
|
|
#ifndef LIGHTNING_COMMON_MEMLEAK_H
|
|
|
|
#define LIGHTNING_COMMON_MEMLEAK_H
|
|
|
|
#include "config.h"
|
2017-12-15 14:26:06 +01:00
|
|
|
#include <ccan/cast/cast.h>
|
2017-12-15 11:17:54 +01:00
|
|
|
#include <ccan/tal/tal.h>
|
2017-12-15 11:18:54 +01:00
|
|
|
#include <inttypes.h>
|
2017-12-15 11:17:54 +01:00
|
|
|
|
|
|
|
#if HAVE_TYPEOF
|
|
|
|
#define memleak_typeof(var) typeof(var)
|
|
|
|
#else
|
|
|
|
#define memleak_typeof(var) void *
|
|
|
|
#endif /* !HAVE_TYPEOF */
|
|
|
|
|
|
|
|
/* Mark a pointer as not being leaked. */
|
2017-12-15 11:22:40 +01:00
|
|
|
#define notleak(p) ((memleak_typeof(p))notleak_((p), false))
|
|
|
|
|
|
|
|
/* Mark a pointer and all its tal children as not being leaked. */
|
|
|
|
#define notleak_with_children(p) ((memleak_typeof(p))notleak_((p), true))
|
2017-12-15 11:17:54 +01:00
|
|
|
|
2017-12-15 11:22:40 +01:00
|
|
|
void *notleak_(const void *ptr, bool plus_children);
|
2017-12-15 11:17:54 +01:00
|
|
|
|
|
|
|
struct htable;
|
|
|
|
|
2018-08-24 07:20:06 +02:00
|
|
|
/* Initialize memleak detection */
|
|
|
|
void memleak_init(void);
|
2017-12-15 11:17:54 +01:00
|
|
|
|
|
|
|
/* Free memleak detection. */
|
|
|
|
void memleak_cleanup(void);
|
|
|
|
|
|
|
|
/* Allocate a htable with all the memory we've allocated. */
|
2017-12-15 11:20:54 +01:00
|
|
|
struct htable *memleak_enter_allocations(const tal_t *ctx,
|
|
|
|
const void *exclude1,
|
|
|
|
const void *exclude2);
|
2017-12-15 11:17:54 +01:00
|
|
|
|
|
|
|
/* Remove any pointers to memory under root */
|
|
|
|
void memleak_remove_referenced(struct htable *memtable, const void *root);
|
|
|
|
|
2018-08-24 07:20:02 +02:00
|
|
|
/* Remove any pointers inside this htable (which is opaque to memleak). */
|
|
|
|
void memleak_remove_htable(struct htable *memtable, const struct htable *ht);
|
|
|
|
|
|
|
|
/* Remove any pointers inside this uintmap (which is opaque to memleak). */
|
|
|
|
#define memleak_remove_uintmap(memtable, umap) \
|
|
|
|
memleak_remove_intmap_(memtable, uintmap_unwrap_(umap))
|
|
|
|
|
|
|
|
struct intmap;
|
|
|
|
void memleak_remove_intmap_(struct htable *memtable, const struct intmap *m);
|
|
|
|
|
2017-12-15 11:17:54 +01:00
|
|
|
/* Mark this pointer as being referenced, and search within for more. */
|
2018-08-24 07:20:06 +02:00
|
|
|
void memleak_scan_region(struct htable *memtable,
|
|
|
|
const void *p, size_t bytelen);
|
2017-12-15 11:17:54 +01:00
|
|
|
|
|
|
|
/* Get (and remove) a leak from memtable, or NULL */
|
2017-12-15 11:18:54 +01:00
|
|
|
const void *memleak_get(struct htable *memtable, const uintptr_t **backtrace);
|
2017-12-15 11:17:54 +01:00
|
|
|
|
|
|
|
#endif /* LIGHTNING_COMMON_MEMLEAK_H */
|