diff --git a/plugins/topology.c b/plugins/topology.c index 4376e56e1..4402c8c25 100644 --- a/plugins/topology.c +++ b/plugins/topology.c @@ -684,6 +684,14 @@ done: return command_finished(cmd, js); } +#if DEVELOPER +static void memleak_mark(struct plugin *p, struct htable *memtable) +{ + memleak_remove_region(memtable, global_gossmap, + tal_bytelen(global_gossmap)); +} +#endif + static const char *init(struct plugin *p, const char *buf UNUSED, const jsmntok_t *config UNUSED) { @@ -694,9 +702,9 @@ static const char *init(struct plugin *p, take(json_out_obj(NULL, NULL, NULL)), "{id:%}", JSON_SCAN(json_to_node_id, &local_id)); - global_gossmap = notleak_with_children(gossmap_load(NULL, - GOSSIP_STORE_FILENAME, - &num_cupdates_rejected)); + global_gossmap = gossmap_load(NULL, + GOSSIP_STORE_FILENAME, + &num_cupdates_rejected); if (!global_gossmap) plugin_err(plugin, "Could not load gossmap %s: %s", GOSSIP_STORE_FILENAME, strerror(errno)); @@ -705,6 +713,9 @@ static const char *init(struct plugin *p, plugin_log(plugin, LOG_DBG, "gossmap ignored %zu channel updates", num_cupdates_rejected); +#if DEVELOPER + plugin_set_memleak_handler(p, memleak_mark); +#endif return NULL; } diff --git a/tests/test_gossip.py b/tests/test_gossip.py index 64110ef68..568634667 100644 --- a/tests/test_gossip.py +++ b/tests/test_gossip.py @@ -1966,6 +1966,22 @@ def test_addgossip(node_factory): l3.rpc.addgossip(badupdate) +def test_topology_leak(node_factory, bitcoind): + l1, l2, l3 = node_factory.line_graph(3) + + l1.rpc.listchannels() + bitcoind.generate_block(5) + + # Wait until l1 sees all the channels. + wait_for(lambda: len(l1.rpc.listchannels()['channels']) == 4) + + # Close and wait for gossip to catchup. + txid = l2.rpc.close(l3.info['id'])['txid'] + bitcoind.generate_block(1, txid) + + wait_for(lambda: len(l1.rpc.listchannels()['channels']) == 2) + + def test_parms_listforwards(node_factory): """ Simple test to ensure that the order of the listforwards