all: no longer need to call htable_clear to free htable contents.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2023-01-12 11:43:14 +10:30
parent f07e37018d
commit 5dfcd15782
11 changed files with 0 additions and 46 deletions

View File

@@ -120,7 +120,6 @@ struct channel *new_full_channel(const tal_t *ctx,
channel->htlcs = tal(channel, struct htlc_map); channel->htlcs = tal(channel, struct htlc_map);
htlc_map_init(channel->htlcs); htlc_map_init(channel->htlcs);
memleak_add_helper(channel->htlcs, memleak_help_htlcmap); memleak_add_helper(channel->htlcs, memleak_help_htlcmap);
tal_add_destructor(channel->htlcs, htlc_map_clear);
} }
return channel; return channel;
} }

View File

@@ -699,8 +699,6 @@ static void destroy_map(struct gossmap *map)
{ {
if (map->mmap) if (map->mmap)
munmap(map->mmap, map->map_size); munmap(map->mmap, map->map_size);
chanidx_htable_clear(map->channels);
nodeidx_htable_clear(map->nodes);
for (size_t i = 0; i < tal_count(map->node_arr); i++) for (size_t i = 0; i < tal_count(map->node_arr); i++)
free(map->node_arr[i].chan_idxs); free(map->node_arr[i].chan_idxs);

View File

@@ -319,7 +319,6 @@ struct htable *memleak_start(const tal_t *ctx)
call_memleak_helpers(memtable, NULL); call_memleak_helpers(memtable, NULL);
} }
tal_add_destructor(memtable, htable_clear);
return memtable; return memtable;
} }

View File

@@ -21,17 +21,11 @@ static size_t rehash(const void *key, void *unused)
return ptr2int(key); return ptr2int(key);
} }
static void destroy_msg_map(struct htable *ht)
{
htable_clear(ht);
}
static struct htable *new_msg_map(const tal_t *ctx) static struct htable *new_msg_map(const tal_t *ctx)
{ {
struct htable *ht = tal(ctx, struct htable); struct htable *ht = tal(ctx, struct htable);
htable_init(ht, rehash, NULL); htable_init(ht, rehash, NULL);
tal_add_destructor(ht, destroy_msg_map);
return ht; return ht;
} }

View File

@@ -407,11 +407,6 @@ static void move_broadcast(struct offmap *offmap,
offmap_del(offmap, omap); offmap_del(offmap, omap);
} }
static void destroy_offmap(struct offmap *offmap)
{
offmap_clear(offmap);
}
/** /**
* Rewrite the on-disk gossip store, compacting it along the way * Rewrite the on-disk gossip store, compacting it along the way
* *
@@ -453,7 +448,6 @@ bool gossip_store_compact(struct gossip_store *gs)
/* Walk old file, copy everything and remember new offsets. */ /* Walk old file, copy everything and remember new offsets. */
offmap = tal(tmpctx, struct offmap); offmap = tal(tmpctx, struct offmap);
offmap_init_sized(offmap, gs->count); offmap_init_sized(offmap, gs->count);
tal_add_destructor(offmap, destroy_offmap);
/* Start by writing all channel announcements and updates. */ /* Start by writing all channel announcements and updates. */
off = 1; off = 1;

View File

@@ -127,7 +127,6 @@ static struct node_map *new_node_map(const tal_t *ctx)
{ {
struct node_map *map = tal(ctx, struct node_map); struct node_map *map = tal(ctx, struct node_map);
node_map_init(map); node_map_init(map);
tal_add_destructor(map, node_map_clear);
return map; return map;
} }
@@ -204,9 +203,6 @@ static void destroy_routing_state(struct routing_state *rstate)
chan; chan;
chan = uintmap_after(&rstate->chanmap, &idx)) chan = uintmap_after(&rstate->chanmap, &idx))
free_chan(rstate, chan); free_chan(rstate, chan);
/* Free up our htables */
pending_cannouncement_map_clear(rstate->pending_cannouncements);
} }
/* We don't check this when loading from the gossip_store: that would break /* We don't check this when loading from the gossip_store: that would break
@@ -356,10 +352,6 @@ static void destroy_node(struct node *node, struct routing_state *rstate)
/* These remove themselves from chans[]. */ /* These remove themselves from chans[]. */
while ((c = first_chan(node, &i)) != NULL) while ((c = first_chan(node, &i)) != NULL)
free_chan(rstate, c); free_chan(rstate, c);
/* Free htable if we need. */
if (node_uses_chan_map(node))
chan_map_clear(node->chan_map);
} }
struct node *get_node(struct routing_state *rstate, struct node *get_node(struct routing_state *rstate,
@@ -2077,8 +2069,6 @@ void remove_all_gossip(struct routing_state *rstate)
* manually. */ * manually. */
while ((n = node_map_first(rstate->nodes, &nit)) != NULL) { while ((n = node_map_first(rstate->nodes, &nit)) != NULL) {
tal_del_destructor2(n, destroy_node, rstate); tal_del_destructor2(n, destroy_node, rstate);
if (node_uses_chan_map(n))
chan_map_clear(n->chan_map);
node_map_del(rstate->nodes, n); node_map_del(rstate->nodes, n);
tal_free(n); tal_free(n);
} }

View File

@@ -1259,10 +1259,6 @@ stop:
/* Now close database */ /* Now close database */
ld->wallet->db = tal_free(ld->wallet->db); ld->wallet->db = tal_free(ld->wallet->db);
/* Clean our our HTLC maps, since they use malloc. */
htlc_in_map_clear(ld->htlcs_in);
htlc_out_map_clear(ld->htlcs_out);
remove(ld->pidfile); remove(ld->pidfile);
/* FIXME: pay can have children off tmpctx which unlink from /* FIXME: pay can have children off tmpctx which unlink from

View File

@@ -2824,7 +2824,6 @@ void htlcs_resubmit(struct lightningd *ld,
} }
/* Don't leak memory! */ /* Don't leak memory! */
htlc_in_map_clear(unconnected_htlcs_in);
tal_free(unconnected_htlcs_in); tal_free(unconnected_htlcs_in);
} }

View File

@@ -533,7 +533,6 @@ static struct command_result *listsendpays_done(struct command *cmd,
assert(pm != NULL); assert(pm != NULL);
add_new_entry(ret, buf, pm); add_new_entry(ret, buf, pm);
} }
pay_map_clear(pay_map);
json_array_end(ret); json_array_end(ret);
return command_finished(cmd, ret); return command_finished(cmd, ret);
} }

View File

@@ -1850,8 +1850,6 @@ static bool test_htlc_crud(struct lightningd *ld, const tal_t *ctx)
* twisted */ * twisted */
tal_free(hin); tal_free(hin);
tal_free(hout); tal_free(hout);
htlc_in_map_clear(htlcs_in);
htlc_out_map_clear(htlcs_out);
return true; return true;
} }

View File

@@ -52,16 +52,10 @@ struct outpointfilter {
struct outpointset *set; struct outpointset *set;
}; };
static void destroy_txfilter(struct txfilter *filter)
{
scriptpubkeyset_clear(&filter->scriptpubkeyset);
}
struct txfilter *txfilter_new(const tal_t *ctx) struct txfilter *txfilter_new(const tal_t *ctx)
{ {
struct txfilter *filter = tal(ctx, struct txfilter); struct txfilter *filter = tal(ctx, struct txfilter);
scriptpubkeyset_init(&filter->scriptpubkeyset); scriptpubkeyset_init(&filter->scriptpubkeyset);
tal_add_destructor(filter, destroy_txfilter);
return filter; return filter;
} }
@@ -123,16 +117,10 @@ void outpointfilter_remove(struct outpointfilter *of,
outpointset_del(of->set, outpoint); outpointset_del(of->set, outpoint);
} }
static void destroy_outpointfilter(struct outpointfilter *opf)
{
outpointset_clear(opf->set);
}
struct outpointfilter *outpointfilter_new(tal_t *ctx) struct outpointfilter *outpointfilter_new(tal_t *ctx)
{ {
struct outpointfilter *opf = tal(ctx, struct outpointfilter); struct outpointfilter *opf = tal(ctx, struct outpointfilter);
opf->set = tal(opf, struct outpointset); opf->set = tal(opf, struct outpointset);
outpointset_init(opf->set); outpointset_init(opf->set);
tal_add_destructor(opf, destroy_outpointfilter);
return opf; return opf;
} }