2017-12-15 11:17:54 +01:00
|
|
|
#ifndef LIGHTNING_COMMON_MEMLEAK_H
|
|
|
|
#define LIGHTNING_COMMON_MEMLEAK_H
|
|
|
|
#include "config.h"
|
|
|
|
#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. */
|
|
|
|
#define notleak(p) ((memleak_typeof(p))notleak_(p))
|
|
|
|
|
|
|
|
#if DEVELOPER
|
|
|
|
void *notleak_(const void *ptr);
|
|
|
|
|
|
|
|
struct htable;
|
2017-12-15 11:18:54 +01:00
|
|
|
struct backtrace_state;
|
2017-12-15 11:17:54 +01:00
|
|
|
|
|
|
|
/* Initialize memleak detection, with this as the root */
|
2017-12-15 11:18:54 +01:00
|
|
|
void memleak_init(const tal_t *root, struct backtrace_state *bstate);
|
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. */
|
|
|
|
struct htable *memleak_enter_allocations(const tal_t *ctx, const void *exclude);
|
|
|
|
|
|
|
|
/* Remove any pointers to memory under root */
|
|
|
|
void memleak_remove_referenced(struct htable *memtable, const void *root);
|
|
|
|
|
|
|
|
/* Mark this pointer as being referenced, and search within for more. */
|
|
|
|
void memleak_scan_region(struct htable *memtable, const void *p);
|
|
|
|
|
|
|
|
/* 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
|
|
|
|
|
|
|
#else /* ... !DEVELOPER */
|
|
|
|
static inline void *notleak_(const void *ptr)
|
|
|
|
{
|
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
#endif /* !DEVELOPER */
|
|
|
|
|
|
|
|
#endif /* LIGHTNING_COMMON_MEMLEAK_H */
|