From 9bf19426e04fcf79c798d8b5d7edf5ab615816e9 Mon Sep 17 00:00:00 2001 From: Rafael Zalamena Date: Thu, 15 Dec 2022 09:54:33 -0300 Subject: [PATCH] ospfd: fix SPF table memory leak After `free()`ing a table also set it to NULL so when the instance release function is called we know whether the pointer is valid or not. Signed-off-by: Rafael Zalamena --- ospfd/ospf_spf.c | 10 ++++++---- ospfd/ospfd.c | 4 ++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/ospfd/ospf_spf.c b/ospfd/ospf_spf.c index 4f60ce22a9..58fcbfa4a9 100644 --- a/ospfd/ospf_spf.c +++ b/ospfd/ospf_spf.c @@ -1956,9 +1956,10 @@ static void ospf_spf_calculate_schedule_worker(struct thread *thread) rt_time = monotime_since(&start_time, NULL); /* Free old all routers routing table */ - if (ospf->oall_rtrs) - /* ospf_route_delete (ospf->old_rtrs); */ + if (ospf->oall_rtrs) { ospf_rtrs_free(ospf->oall_rtrs); + ospf->oall_rtrs = NULL; + } /* Update all routers routing table */ ospf->oall_rtrs = ospf->all_rtrs; @@ -1967,9 +1968,10 @@ static void ospf_spf_calculate_schedule_worker(struct thread *thread) ospf_apiserver_notify_reachable(ospf->oall_rtrs, ospf->all_rtrs); #endif /* Free old ABR/ASBR routing table */ - if (ospf->old_rtrs) - /* ospf_route_delete (ospf->old_rtrs); */ + if (ospf->old_rtrs) { ospf_rtrs_free(ospf->old_rtrs); + ospf->old_rtrs = NULL; + } /* Update ABR/ASBR routing table */ ospf->old_rtrs = ospf->new_rtrs; diff --git a/ospfd/ospfd.c b/ospfd/ospfd.c index 2403b567a5..a5d40ad176 100644 --- a/ospfd/ospfd.c +++ b/ospfd/ospfd.c @@ -852,6 +852,10 @@ static void ospf_finish_final(struct ospf *ospf) ospf_route_delete(ospf, ospf->new_table); ospf_route_table_free(ospf->new_table); } + if (ospf->oall_rtrs) + ospf_rtrs_free(ospf->oall_rtrs); + if (ospf->all_rtrs) + ospf_rtrs_free(ospf->all_rtrs); if (ospf->old_rtrs) ospf_rtrs_free(ospf->old_rtrs); if (ospf->new_rtrs) -- 2.39.5