From 3f6d6a5db80fd465e15383ee96867153578fc316 Mon Sep 17 00:00:00 2001 From: Don Slice Date: Mon, 27 Jun 2016 04:34:32 -0700 Subject: [PATCH] zebra/ospf/ospf6: Fix several memory leaks on if up/down Resolved several memory leaks caused by ifdown/ifup the vrf device or a swp port. For bgp/zebra/ospf/ospf6, bouncing the vrf device would cause a linked list, Interface, and route-table to get leaked. For ospf6, bouncing the swp device also caused leaks of Connected and Prefix entries. Ticket: CM-10841 Signed-off-by: Don Slice Reviewed-By: Donald Sharp Testing Done: Manual testing, bgp and ospf mins passed, smokes had fewer failures than base --- lib/if.c | 6 ++++++ lib/vrf.c | 3 +-- ospf6d/ospf6_spf.c | 1 + ospf6d/ospf6_zebra.c | 2 ++ zebra/interface.c | 7 +++++++ zebra/rt_netlink.c | 4 +++- zebra/zebra_vrf.c | 3 ++- 7 files changed, 22 insertions(+), 4 deletions(-) diff --git a/lib/if.c b/lib/if.c index 97edf1769a..8f1461326f 100644 --- a/lib/if.c +++ b/lib/if.c @@ -1292,6 +1292,12 @@ if_terminate (struct list **intf_list) if (ifp == NULL) break; + if (ifp->node) + { + ifp->node->info = NULL; + route_unlock_node (ifp->node); + } + if_delete (ifp); } diff --git a/lib/vrf.c b/lib/vrf.c index 9615ecfab6..bffcbca54e 100644 --- a/lib/vrf.c +++ b/lib/vrf.c @@ -272,8 +272,7 @@ vrf_delete (struct vrf *vrf) if (vrf_master.vrf_delete_hook) (*vrf_master.vrf_delete_hook) (vrf->vrf_id, vrf->name, &vrf->info); - if (CHECK_FLAG (vrf->status, VRF_ACTIVE)) - if_terminate (&vrf->iflist); + if_terminate (&vrf->iflist); if (vrf->node) { diff --git a/ospf6d/ospf6_spf.c b/ospf6d/ospf6_spf.c index 5b77bf00a6..ab1213ebb6 100644 --- a/ospf6d/ospf6_spf.c +++ b/ospf6d/ospf6_spf.c @@ -158,6 +158,7 @@ ospf6_vertex_create (struct ospf6_lsa *lsa) static void ospf6_vertex_delete (struct ospf6_vertex *v) { + list_delete(v->nh_list); list_delete (v->child_list); XFREE (MTYPE_OSPF6_VERTEX, v); } diff --git a/ospf6d/ospf6_zebra.c b/ospf6d/ospf6_zebra.c index 9c738233b4..93ec1f2ce0 100644 --- a/ospf6d/ospf6_zebra.c +++ b/ospf6d/ospf6_zebra.c @@ -202,6 +202,8 @@ ospf6_zebra_if_address_update_delete (int command, struct zclient *zclient, ospf6_interface_state_update (c->ifp); } + connected_free (c); + return 0; } diff --git a/zebra/interface.c b/zebra/interface.c index 9d0a0c9d3d..87a426fdc4 100644 --- a/zebra/interface.c +++ b/zebra/interface.c @@ -120,6 +120,13 @@ if_zebra_delete_hook (struct interface *ifp) /* Free installed address chains tree. */ if (zebra_if->ipv4_subnets) route_table_finish (zebra_if->ipv4_subnets); + #if defined (HAVE_RTADV) + + struct rtadvconf *rtadv; + + rtadv = &zebra_if->rtadv; + list_free (rtadv->AdvPrefixList); + #endif /* HAVE_RTADV */ XFREE (MTYPE_TMP, zebra_if); } diff --git a/zebra/rt_netlink.c b/zebra/rt_netlink.c index 72951322ff..481ff781e3 100644 --- a/zebra/rt_netlink.c +++ b/zebra/rt_netlink.c @@ -1433,7 +1433,9 @@ netlink_link_change (struct sockaddr_nl *snl, struct nlmsghdr *h, zlog_debug ("RTM_DELLINK for %s(%u)", name, ifp->ifindex); UNSET_FLAG(ifp->status, ZEBRA_INTERFACE_VRF_LOOPBACK); - if_delete_update (ifp); + + if (!vrf_device) + if_delete_update (ifp); } return 0; diff --git a/zebra/zebra_vrf.c b/zebra/zebra_vrf.c index 382d5e4a52..46dc29d102 100644 --- a/zebra/zebra_vrf.c +++ b/zebra/zebra_vrf.c @@ -79,7 +79,8 @@ zebra_vrf_new (vrf_id_t vrf_id, const char *name, void **info) { struct zebra_vrf *zvrf = *info; - zlog_info ("ZVRF %s with id %u", name, vrf_id); + if (IS_ZEBRA_DEBUG_EVENT) + zlog_info ("ZVRF %s with id %u", name, vrf_id); if (! zvrf) { -- 2.39.5