]> git.proxmox.com Git - mirror_frr.git/commitdiff
ospfd: fix SPF table memory leak
authorRafael Zalamena <rzalamena@opensourcerouting.org>
Thu, 15 Dec 2022 12:54:33 +0000 (09:54 -0300)
committerRafael Zalamena <rzalamena@opensourcerouting.org>
Tue, 20 Dec 2022 11:51:13 +0000 (08:51 -0300)
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 <rzalamena@opensourcerouting.org>
ospfd/ospf_spf.c
ospfd/ospfd.c

index 4f60ce22a9ecbbb5200be837e72df77d3265749e..58fcbfa4a98f080fbc3d12d0fe734aad5de03249 100644 (file)
@@ -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;
index 2403b567a5744144008c0679f39af7a1290ffdbe..a5d40ad176ee599b0c2bb115503ab72168aa0f4d 100644 (file)
@@ -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)