diff --git a/plugins/libplugin.c b/plugins/libplugin.c index 8f20ac34a..285af577c 100644 --- a/plugins/libplugin.c +++ b/plugins/libplugin.c @@ -99,6 +99,11 @@ struct plugin { const char **notif_topics; size_t num_notif_topics; + +#if DEVELOPER + /* Lets them remove ptrs from leak detection. */ + void (*mark_mem)(struct plugin *plugin, struct htable *memtable); +#endif }; /* command_result is mainly used as a compile-time check to encourage you @@ -1197,9 +1202,19 @@ static void memleak_check(struct plugin *plugin, struct command *cmd) /* We know usage strings are referred to. */ memleak_remove_strmap(memtable, &cmd->plugin->usagemap); + if (plugin->mark_mem) + plugin->mark_mem(plugin, memtable); + memleak_plugin = plugin; dump_memleak(memtable, log_memleak); } + +void plugin_set_memleak_handler(struct plugin *plugin, + void (*mark_mem)(struct plugin *plugin, + struct htable *memtable)) +{ + plugin->mark_mem = mark_mem; +} #endif /* DEVELOPER */ static void ld_command_handle(struct plugin *plugin, @@ -1498,6 +1513,9 @@ static struct plugin *new_plugin(const tal_t *ctx, tal_arr_expand(&p->opts, o); } +#if DEVELOPER + p->mark_mem = NULL; +#endif return p; } diff --git a/plugins/libplugin.h b/plugins/libplugin.h index 0b1bf14ca..8ff96612f 100644 --- a/plugins/libplugin.h +++ b/plugins/libplugin.h @@ -342,4 +342,11 @@ struct createonion_response *json_to_createonion_response(const tal_t *ctx, struct route_hop *json_to_route(const tal_t *ctx, const char *buffer, const jsmntok_t *toks); +#if DEVELOPER +struct htable; +void plugin_set_memleak_handler(struct plugin *plugin, + void (*mark_mem)(struct plugin *plugin, + struct htable *memtable)); +#endif /* DEVELOPER */ + #endif /* LIGHTNING_PLUGINS_LIBPLUGIN_H */