diff --git a/isisd/isis_spf.c b/isisd/isis_spf.c index 0d1a5db0d6..89e751b4e6 100644 --- a/isisd/isis_spf.c +++ b/isisd/isis_spf.c @@ -1297,6 +1297,7 @@ static void spf_adj_get_reverse_metrics(struct isis_spftree *spftree) if (lsp_adj == NULL || lsp_adj->hdr.rem_lifetime == 0) { /* Delete one-way adjacency. */ listnode_delete(spftree->sadj_list, sadj); + isis_spf_adj_free(sadj); continue; } @@ -1313,6 +1314,7 @@ static void spf_adj_get_reverse_metrics(struct isis_spftree *spftree) if (args.reverse_metric == UINT32_MAX) { /* Delete one-way adjacency. */ listnode_delete(spftree->sadj_list, sadj); + isis_spf_adj_free(sadj); continue; } sadj->metric = args.reverse_metric; diff --git a/lib/linklist.c b/lib/linklist.c index d1b57084ef..d2a29b7ed1 100644 --- a/lib/linklist.c +++ b/lib/linklist.c @@ -28,6 +28,37 @@ DEFINE_MTYPE_STATIC(LIB, LINK_LIST, "Link List"); DEFINE_MTYPE_STATIC(LIB, LINK_NODE, "Link Node"); +/* these *do not* cleanup list nodes and referenced data, as the functions + * do - these macros simply {de,at}tach a listnode from/to a list. + */ + +/* List node attach macro. */ +#define LISTNODE_ATTACH(L, N) \ + do { \ + (N)->prev = (L)->tail; \ + (N)->next = NULL; \ + if ((L)->head == NULL) \ + (L)->head = (N); \ + else \ + (L)->tail->next = (N); \ + (L)->tail = (N); \ + (L)->count++; \ + } while (0) + +/* List node detach macro. */ +#define LISTNODE_DETACH(L, N) \ + do { \ + if ((N)->prev) \ + (N)->prev->next = (N)->next; \ + else \ + (L)->head = (N)->next; \ + if ((N)->next) \ + (N)->next->prev = (N)->prev; \ + else \ + (L)->tail = (N)->prev; \ + (L)->count--; \ + } while (0) + struct list *list_new(void) { return XCALLOC(MTYPE_LINK_LIST, sizeof(struct list)); diff --git a/lib/linklist.h b/lib/linklist.h index 1452145218..e7594728f1 100644 --- a/lib/linklist.h +++ b/lib/linklist.h @@ -349,37 +349,6 @@ extern struct list *list_dup(struct list *list); (node) != NULL && ((data) = static_cast(data, listgetdata(node)), 1); \ (node) = listnextnode(node), ((data) = NULL) -/* these *do not* cleanup list nodes and referenced data, as the functions - * do - these macros simply {de,at}tach a listnode from/to a list. - */ - -/* List node attach macro. */ -#define LISTNODE_ATTACH(L, N) \ - do { \ - (N)->prev = (L)->tail; \ - (N)->next = NULL; \ - if ((L)->head == NULL) \ - (L)->head = (N); \ - else \ - (L)->tail->next = (N); \ - (L)->tail = (N); \ - (L)->count++; \ - } while (0) - -/* List node detach macro. */ -#define LISTNODE_DETACH(L, N) \ - do { \ - if ((N)->prev) \ - (N)->prev->next = (N)->next; \ - else \ - (L)->head = (N)->next; \ - if ((N)->next) \ - (N)->next->prev = (N)->prev; \ - else \ - (L)->tail = (N)->prev; \ - (L)->count--; \ - } while (0) - extern struct listnode *listnode_lookup_nocheck(struct list *list, void *data); /* diff --git a/ospf6d/ospf6_interface.c b/ospf6d/ospf6_interface.c index ed228f46ae..1c045cba07 100644 --- a/ospf6d/ospf6_interface.c +++ b/ospf6d/ospf6_interface.c @@ -1242,7 +1242,8 @@ static int ospf6_interface_show(struct vty *vty, struct interface *ifp, } } - json_auth = json_object_new_object(); + if (use_json) + json_auth = json_object_new_object(); if (oi->at_data.flags != 0) { if (use_json) { if (CHECK_FLAG(oi->at_data.flags, diff --git a/zebra/zebra_dplane.c b/zebra/zebra_dplane.c index 6b9005d645..c189408b57 100644 --- a/zebra/zebra_dplane.c +++ b/zebra/zebra_dplane.c @@ -833,20 +833,8 @@ static void dplane_ctx_free_internal(struct zebra_dplane_ctx *ctx) break; case DPLANE_OP_IPTABLE_ADD: case DPLANE_OP_IPTABLE_DELETE: - if (ctx->u.iptable.interface_name_list) { - struct listnode *node, *nnode; - char *ifname; - - for (ALL_LIST_ELEMENTS( - ctx->u.iptable.interface_name_list, node, - nnode, ifname)) { - LISTNODE_DETACH( - ctx->u.iptable.interface_name_list, - node); - XFREE(MTYPE_DP_NETFILTER, ifname); - } + if (ctx->u.iptable.interface_name_list) list_delete(&ctx->u.iptable.interface_name_list); - } break; case DPLANE_OP_GRE_SET: case DPLANE_OP_INTF_NETCONFIG: @@ -3476,6 +3464,11 @@ static int dplane_ctx_rule_init(struct zebra_dplane_ctx *ctx, return AOK; } +static void zebra_dplane_interface_name_list_deletion(void *data) +{ + XFREE(MTYPE_DP_NETFILTER, data); +} + /** * dplane_ctx_iptable_init() - Initialize a context block for a PBR iptable * update. @@ -3509,9 +3502,10 @@ static int dplane_ctx_iptable_init(struct zebra_dplane_ctx *ctx, ctx->zd_vrf_id = iptable->vrf_id; memcpy(&ctx->u.iptable, iptable, sizeof(struct zebra_pbr_iptable)); - ctx->u.iptable.interface_name_list = NULL; if (iptable->nb_interface > 0) { ctx->u.iptable.interface_name_list = list_new(); + ctx->u.iptable.interface_name_list->del = + zebra_dplane_interface_name_list_deletion; for (ALL_LIST_ELEMENTS_RO(iptable->interface_name_list, node, ifname)) { listnode_add(ctx->u.iptable.interface_name_list, diff --git a/zebra/zebra_routemap.c b/zebra/zebra_routemap.c index 13d1995d58..066ef8a8d0 100644 --- a/zebra/zebra_routemap.c +++ b/zebra/zebra_routemap.c @@ -1818,6 +1818,23 @@ static void zebra_route_map_event(const char *rmap_name) route_map_notify_dependencies(rmap_name, RMAP_EVENT_MATCH_ADDED); } +void zebra_routemap_vrf_delete(struct zebra_vrf *zvrf) +{ + afi_t afi; + uint8_t type; + + for (afi = AFI_IP; afi < AFI_MAX; afi++) { + for (type = 0; type <= ZEBRA_ROUTE_MAX; type++) { + if (PROTO_RM_NAME(zvrf, afi, type)) + XFREE(MTYPE_ROUTE_MAP_NAME, + PROTO_RM_NAME(zvrf, afi, type)); + if (NHT_RM_NAME(zvrf, afi, type)) + XFREE(MTYPE_ROUTE_MAP_NAME, + NHT_RM_NAME(zvrf, afi, type)); + } + } +} + /* ip protocol configuration write function */ void zebra_routemap_config_write_protocol(struct vty *vty, struct zebra_vrf *zvrf) diff --git a/zebra/zebra_routemap.h b/zebra/zebra_routemap.h index 3f58e14e10..02b01fa53a 100644 --- a/zebra/zebra_routemap.h +++ b/zebra/zebra_routemap.h @@ -50,6 +50,8 @@ zebra_nht_route_map_check(afi_t afi, int client_proto, const struct prefix *p, struct zebra_vrf *zvrf, struct route_entry *, struct nexthop *nexthop); +extern void zebra_routemap_vrf_delete(struct zebra_vrf *zvrf); + #ifdef __cplusplus } #endif diff --git a/zebra/zebra_vrf.c b/zebra/zebra_vrf.c index c99aa2e8ff..be5e91495f 100644 --- a/zebra/zebra_vrf.c +++ b/zebra/zebra_vrf.c @@ -268,6 +268,7 @@ static int zebra_vrf_delete(struct vrf *vrf) /* Cleanup EVPN states for vrf */ zebra_vxlan_vrf_delete(zvrf); + zebra_routemap_vrf_delete(zvrf); list_delete_all_node(zvrf->rid_all_sorted_list); list_delete_all_node(zvrf->rid_lo_sorted_list);