mirror of
https://github.com/aljazceru/lightning.git
synced 2026-02-18 04:24:28 +01:00
common/memleak: hoist strmap helper from out of lightningd/memdump.c
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
committed by
Christian Decker
parent
a5fee67b91
commit
1f7fb33563
@@ -160,6 +160,24 @@ void memleak_remove_intmap_(struct htable *memtable, const struct intmap *m)
|
||||
memleak_remove_region(memtable, p, tal_bytelen(p));
|
||||
}
|
||||
|
||||
static bool handle_strmap(const char *member, void *p, void *memtable_)
|
||||
{
|
||||
struct htable *memtable = memtable_;
|
||||
|
||||
/* membername may *not* be a tal ptr, but it can be! */
|
||||
pointer_referenced(memtable, member);
|
||||
memleak_remove_region(memtable, p, tal_bytelen(p));
|
||||
|
||||
/* Keep going */
|
||||
return true;
|
||||
}
|
||||
|
||||
/* FIXME: If strmap used tal, this wouldn't be necessary! */
|
||||
void memleak_remove_strmap_(struct htable *memtable, const struct strmap *m)
|
||||
{
|
||||
strmap_iterate_(m, handle_strmap, memtable);
|
||||
}
|
||||
|
||||
static bool ptr_match(const void *candidate, void *ptr)
|
||||
{
|
||||
return candidate == ptr;
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define LIGHTNING_COMMON_MEMLEAK_H
|
||||
#include "config.h"
|
||||
#include <ccan/cast/cast.h>
|
||||
#include <ccan/strmap/strmap.h>
|
||||
#include <ccan/tal/tal.h>
|
||||
#include <ccan/typesafe_cb/typesafe_cb.h>
|
||||
#include <inttypes.h>
|
||||
@@ -109,6 +110,11 @@ void memleak_remove_htable(struct htable *memtable, const struct htable *ht);
|
||||
struct intmap;
|
||||
void memleak_remove_intmap_(struct htable *memtable, const struct intmap *m);
|
||||
|
||||
/* Remove any pointers inside this strmap (which is opaque to memleak). */
|
||||
#define memleak_remove_strmap(memtable, strmap) \
|
||||
memleak_remove_strmap_((memtable), tcon_unwrap(strmap))
|
||||
void memleak_remove_strmap_(struct htable *memtable, const struct strmap *m);
|
||||
|
||||
/**
|
||||
* memleak_get: get (and remove) a leak from memtable, or NULL
|
||||
* @memtable: the memtable after all known allocations removed.
|
||||
|
||||
@@ -128,22 +128,6 @@ static void json_add_backtrace(struct json_stream *response,
|
||||
json_array_end(response);
|
||||
}
|
||||
|
||||
static bool handle_strmap(const char *member, void *p, void *memtable_)
|
||||
{
|
||||
struct htable *memtable = memtable_;
|
||||
|
||||
memleak_remove_region(memtable, p, tal_bytelen(p));
|
||||
|
||||
/* Keep going */
|
||||
return true;
|
||||
}
|
||||
|
||||
/* FIXME: If strmap used tal, this wouldn't be necessary! */
|
||||
void memleak_remove_strmap_(struct htable *memtable, const struct strmap *m)
|
||||
{
|
||||
strmap_iterate_(m, handle_strmap, memtable);
|
||||
}
|
||||
|
||||
static void scan_mem(struct command *cmd,
|
||||
struct json_stream *response,
|
||||
struct lightningd *ld,
|
||||
|
||||
@@ -12,9 +12,4 @@ struct subd;
|
||||
void opening_memleak_done(struct command *cmd, struct subd *leaker);
|
||||
void peer_memleak_done(struct command *cmd, struct subd *leaker);
|
||||
|
||||
/* Remove any pointers inside this strmap (which is opaque to memleak). */
|
||||
#define memleak_remove_strmap(memtable, strmap) \
|
||||
memleak_remove_strmap_((memtable), tcon_unwrap(strmap))
|
||||
void memleak_remove_strmap_(struct htable *memtable, const struct strmap *m);
|
||||
|
||||
#endif /* LIGHTNING_LIGHTNINGD_MEMDUMP_H */
|
||||
|
||||
@@ -161,9 +161,6 @@ bool log_status_msg(struct log *log UNNEEDED,
|
||||
const struct node_id *node_id UNNEEDED,
|
||||
const u8 *msg UNNEEDED)
|
||||
{ fprintf(stderr, "log_status_msg called!\n"); abort(); }
|
||||
/* Generated stub for memleak_remove_strmap_ */
|
||||
void memleak_remove_strmap_(struct htable *memtable UNNEEDED, const struct strmap *m UNNEEDED)
|
||||
{ fprintf(stderr, "memleak_remove_strmap_ called!\n"); abort(); }
|
||||
/* Generated stub for new_log */
|
||||
struct log *new_log(const tal_t *ctx UNNEEDED, struct log_book *record UNNEEDED,
|
||||
const struct node_id *default_node_id UNNEEDED,
|
||||
|
||||
@@ -50,9 +50,6 @@ void log_io(struct log *log UNNEEDED, enum log_level dir UNNEEDED,
|
||||
/* Generated stub for log_level_name */
|
||||
const char *log_level_name(enum log_level level UNNEEDED)
|
||||
{ fprintf(stderr, "log_level_name called!\n"); abort(); }
|
||||
/* Generated stub for memleak_remove_strmap_ */
|
||||
void memleak_remove_strmap_(struct htable *memtable UNNEEDED, const struct strmap *m UNNEEDED)
|
||||
{ fprintf(stderr, "memleak_remove_strmap_ called!\n"); abort(); }
|
||||
/* Generated stub for new_log */
|
||||
struct log *new_log(const tal_t *ctx UNNEEDED, struct log_book *record UNNEEDED,
|
||||
const struct node_id *default_node_id UNNEEDED,
|
||||
|
||||
Reference in New Issue
Block a user