diff --git a/common/memleak.c b/common/memleak.c index a07affd3e..597889549 100644 --- a/common/memleak.c +++ b/common/memleak.c @@ -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; diff --git a/common/memleak.h b/common/memleak.h index c7cadab4e..25762460b 100644 --- a/common/memleak.h +++ b/common/memleak.h @@ -2,6 +2,7 @@ #define LIGHTNING_COMMON_MEMLEAK_H #include "config.h" #include +#include #include #include #include @@ -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. diff --git a/lightningd/memdump.c b/lightningd/memdump.c index 2ddda59cb..85695ef86 100644 --- a/lightningd/memdump.c +++ b/lightningd/memdump.c @@ -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, diff --git a/lightningd/memdump.h b/lightningd/memdump.h index 552609987..45c452495 100644 --- a/lightningd/memdump.h +++ b/lightningd/memdump.h @@ -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 */ diff --git a/lightningd/test/run-find_my_abspath.c b/lightningd/test/run-find_my_abspath.c index 3eb28f7fa..b10e03ef6 100644 --- a/lightningd/test/run-find_my_abspath.c +++ b/lightningd/test/run-find_my_abspath.c @@ -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, diff --git a/lightningd/test/run-jsonrpc.c b/lightningd/test/run-jsonrpc.c index 0ab70c68b..b56537605 100644 --- a/lightningd/test/run-jsonrpc.c +++ b/lightningd/test/run-jsonrpc.c @@ -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,