From: Chirag Shah Date: Thu, 13 Jul 2017 20:33:29 +0000 (-0700) Subject: ospfd: Fix memory leaks X-Git-Tag: frr-4.0-dev~462^2~1 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=7f586094bfd6d9e846d67f6ab95cbd652997ad40;p=mirror%2Ffrr.git ospfd: Fix memory leaks Verified ospfd configuraiton with valgrind, Signed-off-by: Chirag Shah --- diff --git a/ospfd/ospf_memory.c b/ospfd/ospf_memory.c index cdc9b929fa..988991e35c 100644 --- a/ospfd/ospf_memory.c +++ b/ospfd/ospf_memory.c @@ -53,3 +53,6 @@ DEFINE_MTYPE(OSPFD, OSPF_IF_PARAMS, "OSPF if params") DEFINE_MTYPE(OSPFD, OSPF_MESSAGE, "OSPF message") DEFINE_MTYPE(OSPFD, OSPF_MPLS_TE, "OSPF MPLS parameters") DEFINE_MTYPE(OSPFD, OSPF_PCE_PARAMS, "OSPF PCE parameters") +DEFINE_MTYPE(OSPFD, OSPF_EXTERNAL, "OSPF External route table") +DEFINE_MTYPE(OSPFD, OSPF_REDISTRIBUTE, "OSPF Redistriute") + diff --git a/ospfd/ospf_memory.h b/ospfd/ospf_memory.h index 5f5960eec7..d91cbd4111 100644 --- a/ospfd/ospf_memory.h +++ b/ospfd/ospf_memory.h @@ -52,5 +52,7 @@ DECLARE_MTYPE(OSPF_IF_PARAMS) DECLARE_MTYPE(OSPF_MESSAGE) DECLARE_MTYPE(OSPF_MPLS_TE) DECLARE_MTYPE(OSPF_PCE_PARAMS) +DECLARE_MTYPE(OSPF_EXTERNAL) +DECLARE_MTYPE(OSPF_REDISTRIBUTE) #endif /* _QUAGGA_OSPF_MEMORY_H */ diff --git a/ospfd/ospf_zebra.c b/ospfd/ospf_zebra.c index c6b0955dab..5839eb40ec 100644 --- a/ospfd/ospf_zebra.c +++ b/ospfd/ospf_zebra.c @@ -628,7 +628,8 @@ struct ospf_external *ospf_external_add(u_char type, u_short instance) om->external[type] = list_new(); ext_list = om->external[type]; - ext = (struct ospf_external *)calloc(1, sizeof(struct ospf_external)); + ext = (struct ospf_external *)XCALLOC(MTYPE_OSPF_EXTERNAL, + sizeof(struct ospf_external)); ext->instance = instance; EXTERNAL_INFO(ext) = route_table_init(); @@ -652,6 +653,7 @@ void ospf_external_del(u_char type, u_short instance) list_free(om->external[type]); om->external[type] = NULL; } + XFREE(MTYPE_OSPF_EXTERNAL, ext); } } @@ -687,7 +689,8 @@ struct ospf_redist *ospf_redist_add(struct ospf *ospf, u_char type, ospf->redist[type] = list_new(); red_list = ospf->redist[type]; - red = (struct ospf_redist *)calloc(1, sizeof(struct ospf_redist)); + red = (struct ospf_redist *)XCALLOC(MTYPE_OSPF_REDISTRIBUTE, + sizeof(struct ospf_redist)); red->instance = instance; red->dmetric.type = -1; red->dmetric.value = -1; @@ -709,6 +712,7 @@ void ospf_redist_del(struct ospf *ospf, u_char type, u_short instance) list_free(ospf->redist[type]); ospf->redist[type] = NULL; } + XFREE(MTYPE_OSPF_REDISTRIBUTE, red); } } diff --git a/ospfd/ospfd.c b/ospfd/ospfd.c index cee2244dd9..77378512e5 100644 --- a/ospfd/ospfd.c +++ b/ospfd/ospfd.c @@ -590,6 +590,7 @@ static void ospf_finish_final(struct ospf *ospf) route_unlock_node(rn); } } + route_table_finish(ospf->networks); for (ALL_LIST_ELEMENTS(ospf->areas, node, nnode, area)) { listnode_delete(ospf->areas, area); @@ -655,6 +656,8 @@ static void ospf_finish_final(struct ospf *ospf) } list_delete(ospf->areas); + list_delete(ospf->oi_write_q); + list_delete(ospf->oiflist); for (i = ZEBRA_ROUTE_SYSTEM; i <= ZEBRA_ROUTE_MAX; i++) { struct list *ext_list; @@ -752,6 +755,7 @@ static void ospf_area_free(struct ospf_area *area) LSDB_LOOP(OPAQUE_LINK_LSDB(area), rn, lsa) ospf_discard_from_db(area->ospf, area->lsdb, lsa); + ospf_opaque_type10_lsa_term(area); ospf_lsdb_delete_all(area->lsdb); ospf_lsdb_free(area->lsdb);