Skip to content

Commit

Permalink
gossipd: fix uninitialized free on short_route in goto path
Browse files Browse the repository at this point in the history
Fix a path where tal_free is called on an uninitialized variable

If the first `goto bad_total` executes, then that path has
uninitialized `short_route` but bad_total passes through to `out`
whose first call is tal_free(short_route).

This was noticed by a maybe-uninitialized heuristic on gcc 7.4.0:

gossipd/routing.c: In function ‘find_shorter_route’:
gossipd/routing.c:1096:2: error: ‘short_route’ may be used
uninitialized in this function [-Werror=maybe-uninitialized]
  tal_free(short_route);

Reported-by: @ZmnSCPxj <ElementsProject#2674 (comment)>
Signed-off-by: William Casarin <[email protected]>
  • Loading branch information
jb55 authored and rustyrussell committed Jun 3, 2019
1 parent 4640d18 commit 3f035cb
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion gossipd/routing.c
Original file line number Diff line number Diff line change
Expand Up @@ -988,7 +988,7 @@ find_shorter_route(const tal_t *ctx, struct routing_state *rstate,
struct amount_msat *fee)
{
struct unvisited *unvisited;
struct chan **short_route;
struct chan **short_route = NULL;
struct amount_msat long_cost, short_cost, cost_diff;
u64 min_bias, max_bias;
double riskfactor;
Expand Down

0 comments on commit 3f035cb

Please sign in to comment.