mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-20 15:44:21 +01:00
gossipd: free channels in routing_state destructor.
Cleans up the tests. Suggested-by: @ZmnSCPxj Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -154,6 +154,16 @@ struct chan *next_chan(const struct node *node, struct chan_map_iter *i)
|
|||||||
return chan_map_next(&node->chans.map, i);
|
return chan_map_next(&node->chans.map, i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void destroy_routing_state(struct routing_state *rstate)
|
||||||
|
{
|
||||||
|
/* Since we omitted destructors on these, clean up manually */
|
||||||
|
u64 idx;
|
||||||
|
for (struct chan *chan = uintmap_first(&rstate->chanmap, &idx);
|
||||||
|
chan;
|
||||||
|
chan = uintmap_after(&rstate->chanmap, &idx))
|
||||||
|
free_chan(rstate, chan);
|
||||||
|
}
|
||||||
|
|
||||||
struct routing_state *new_routing_state(const tal_t *ctx,
|
struct routing_state *new_routing_state(const tal_t *ctx,
|
||||||
const struct chainparams *chainparams,
|
const struct chainparams *chainparams,
|
||||||
const struct node_id *local_id,
|
const struct node_id *local_id,
|
||||||
@@ -188,6 +198,7 @@ struct routing_state *new_routing_state(const tal_t *ctx,
|
|||||||
} else
|
} else
|
||||||
rstate->gossip_time = NULL;
|
rstate->gossip_time = NULL;
|
||||||
#endif
|
#endif
|
||||||
|
tal_add_destructor(rstate, destroy_routing_state);
|
||||||
|
|
||||||
return rstate;
|
return rstate;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -278,13 +278,6 @@ int main(int argc, char *argv[])
|
|||||||
if (route_lengths[i])
|
if (route_lengths[i])
|
||||||
printf(" Length %zu: %zu\n", i, route_lengths[i]);
|
printf(" Length %zu: %zu\n", i, route_lengths[i]);
|
||||||
|
|
||||||
/* Since we omitted destructors on these, clean up manually */
|
|
||||||
u64 idx;
|
|
||||||
for (struct chan *chan = uintmap_first(&rstate->chanmap, &idx);
|
|
||||||
chan;
|
|
||||||
chan = uintmap_after(&rstate->chanmap, &idx))
|
|
||||||
free_chan(rstate, chan);
|
|
||||||
|
|
||||||
tal_free(tmpctx);
|
tal_free(tmpctx);
|
||||||
secp256k1_context_destroy(secp256k1_ctx);
|
secp256k1_context_destroy(secp256k1_ctx);
|
||||||
opt_free_table();
|
opt_free_table();
|
||||||
|
|||||||
@@ -261,13 +261,6 @@ int main(void)
|
|||||||
ROUTING_MAX_HOPS, &fee);
|
ROUTING_MAX_HOPS, &fee);
|
||||||
assert(!route);
|
assert(!route);
|
||||||
|
|
||||||
/* Since we omitted destructors on these, clean up manually */
|
|
||||||
u64 idx;
|
|
||||||
for (struct chan *chan = uintmap_first(&rstate->chanmap, &idx);
|
|
||||||
chan;
|
|
||||||
chan = uintmap_after(&rstate->chanmap, &idx))
|
|
||||||
free_chan(rstate, chan);
|
|
||||||
|
|
||||||
tal_free(tmpctx);
|
tal_free(tmpctx);
|
||||||
secp256k1_context_destroy(secp256k1_ctx);
|
secp256k1_context_destroy(secp256k1_ctx);
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -278,13 +278,6 @@ int main(void)
|
|||||||
assert(channel_is_between(route[1], &d, &c));
|
assert(channel_is_between(route[1], &d, &c));
|
||||||
assert(amount_msat_eq(fee, AMOUNT_MSAT(0 + 6)));
|
assert(amount_msat_eq(fee, AMOUNT_MSAT(0 + 6)));
|
||||||
|
|
||||||
/* Since we omitted destructors on these, clean up manually */
|
|
||||||
u64 idx;
|
|
||||||
for (struct chan *chan = uintmap_first(&rstate->chanmap, &idx);
|
|
||||||
chan;
|
|
||||||
chan = uintmap_after(&rstate->chanmap, &idx))
|
|
||||||
free_chan(rstate, chan);
|
|
||||||
|
|
||||||
tal_free(tmpctx);
|
tal_free(tmpctx);
|
||||||
secp256k1_context_destroy(secp256k1_ctx);
|
secp256k1_context_destroy(secp256k1_ctx);
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -197,13 +197,6 @@ int main(void)
|
|||||||
last_fee = fee;
|
last_fee = fee;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Since we omitted destructors on these, clean up manually */
|
|
||||||
u64 idx;
|
|
||||||
for (struct chan *chan = uintmap_first(&rstate->chanmap, &idx);
|
|
||||||
chan;
|
|
||||||
chan = uintmap_after(&rstate->chanmap, &idx))
|
|
||||||
free_chan(rstate, chan);
|
|
||||||
|
|
||||||
tal_free(tmpctx);
|
tal_free(tmpctx);
|
||||||
secp256k1_context_destroy(secp256k1_ctx);
|
secp256k1_context_destroy(secp256k1_ctx);
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user