From 7d6fabc5bfb227ed76376a68a820aa243b0d7f53 Mon Sep 17 00:00:00 2001 From: Sander Vrijders Date: Fri, 4 May 2018 11:53:15 +0200 Subject: ipcpd: Fix bad memory handling in LFA policy The Loop-Free Alternates policy had bad memory management in two places. In the calculation of the LFAs a table was freed in the first iteration of a loop, whereas it was still needed in the other iterations. It is now freed outside of the loop. In the alternate PFF the address structs were not freed upon shutdown, this has been added as well. It also fixes some bad initialization in the LFA calculation function. Signed-off-by: Sander Vrijders Signed-off-by: Dimitri Staessens --- src/ipcpd/normal/pol/alternate_pff.c | 1 + src/ipcpd/normal/pol/graph.c | 14 +++++++------- 2 files changed, 8 insertions(+), 7 deletions(-) (limited to 'src/ipcpd/normal/pol') diff --git a/src/ipcpd/normal/pol/alternate_pff.c b/src/ipcpd/normal/pol/alternate_pff.c index cb438c5f..3cb99d9c 100644 --- a/src/ipcpd/normal/pol/alternate_pff.c +++ b/src/ipcpd/normal/pol/alternate_pff.c @@ -234,6 +234,7 @@ void alternate_pff_destroy(struct pff_i * pff_i) htable_destroy(pff_i->table); del_nhops_down(pff_i); + del_addrs(pff_i); pthread_rwlock_destroy(&pff_i->lock); free(pff_i); } diff --git a/src/ipcpd/normal/pol/graph.c b/src/ipcpd/normal/pol/graph.c index 41a27207..007e1047 100644 --- a/src/ipcpd/normal/pol/graph.c +++ b/src/ipcpd/normal/pol/graph.c @@ -612,9 +612,9 @@ int graph_routing_table_lfa(struct graph * graph, pthread_mutex_lock(&graph->lock); for (j = 0; j < PROG_MAX_FLOWS; j++) { - n_dist[i] = NULL; - n_index[i] = -1; - addrs[i] = -1; + n_dist[j] = NULL; + n_index[j] = -1; + addrs[j] = -1; } /* Get the normal next hops routing table. */ @@ -660,17 +660,17 @@ int graph_routing_table_lfa(struct graph * graph, continue; if (n_dist[j][v->index] < - s_dist[n_index[j]] + s_dist[v->index]) { + s_dist[n_index[j]] + s_dist[v->index]) if (add_lfa_to_table(table, v->addr, addrs[j])) goto fail_add_lfa; - } - - free(n_dist[j]); } } pthread_mutex_unlock(&graph->lock); + for (j = 0; j < i; j++) + free(n_dist[j]); + free(s_dist); return 0; -- cgit v1.2.3