Browse Source

gossipd: in DEVELOPER mode, catch missing free_chan()

For memory-usage reasons, struct chan doesn't use a tal destructor, in
favor of us calling free_chan in the right places.

In DEVELOPER mode, we should check that is the case.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
travis-debug
Rusty Russell 5 years ago
parent
commit
a46e880f1d
  1. 15
      gossipd/routing.c

15
gossipd/routing.c

@ -384,6 +384,14 @@ static void remove_chan_from_node(struct routing_state *rstate,
}
}
#if DEVELOPER
/* We make sure that free_chan is called on this chan! */
static void destroy_chan_check(struct chan *chan)
{
assert(chan->scid.u64 == (u64)chan);
}
#endif
/* We used to make this a tal_add_destructor2, but that costs 40 bytes per
* chan, and we only ever explicitly free it anyway. */
void free_chan(struct routing_state *rstate, struct chan *chan)
@ -395,6 +403,10 @@ void free_chan(struct routing_state *rstate, struct chan *chan)
/* Remove from local_disabled_map if it's there. */
chan_map_del(&rstate->local_disabled_map, chan);
#if DEVELOPER
chan->scid.u64 = (u64)chan;
#endif
tal_free(chan);
}
@ -429,6 +441,9 @@ struct chan *new_chan(struct routing_state *rstate,
int n1idx = node_id_idx(id1, id2);
struct node *n1, *n2;
#if DEVELOPER
tal_add_destructor(chan, destroy_chan_check);
#endif
/* We should never add a channel twice */
assert(!uintmap_get(&rstate->chanmap, scid->u64));

Loading…
Cancel
Save