diff options
author | Donald Sharp <sharpd@nvidia.com> | 2023-03-21 13:54:21 +0100 |
---|---|---|
committer | Donald Sharp <sharpd@nvidia.com> | 2023-03-21 13:54:21 +0100 |
commit | d8bc11a592110abdd14d11dfcb2ce623653ecab5 (patch) | |
tree | eee3628586497e48192f65326316f0eb91114011 /zebra | |
parent | Merge pull request #12816 from gpnaveen/stc_rte_err_msg (diff) | |
download | frr-d8bc11a592110abdd14d11dfcb2ce623653ecab5.tar.xz frr-d8bc11a592110abdd14d11dfcb2ce623653ecab5.zip |
*: Add a hash_clean_and_free() function
Add a hash_clean_and_free() function as well as convert
the code to use it. This function also takes a double
pointer to the hash to set it NULL. Also it cleanly
does nothing if the pointer is NULL( as a bunch of
code tested for ).
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
Diffstat (limited to 'zebra')
-rw-r--r-- | zebra/zebra_l2_bridge_if.c | 5 | ||||
-rw-r--r-- | zebra/zebra_mpls.c | 6 | ||||
-rw-r--r-- | zebra/zebra_router.c | 23 | ||||
-rw-r--r-- | zebra/zebra_vxlan_if.c | 5 |
4 files changed, 13 insertions, 26 deletions
diff --git a/zebra/zebra_l2_bridge_if.c b/zebra/zebra_l2_bridge_if.c index b85d39bcd..00450ddd3 100644 --- a/zebra/zebra_l2_bridge_if.c +++ b/zebra/zebra_l2_bridge_if.c @@ -142,10 +142,7 @@ static void *zebra_l2_bridge_vlan_alloc(void *p) static void zebra_l2_bridge_vlan_table_destroy(struct hash *vlan_table) { - if (vlan_table) { - hash_clean(vlan_table, zebra_l2_bridge_vlan_free); - hash_free(vlan_table); - } + hash_clean_and_free(&vlan_table, zebra_l2_bridge_vlan_free); } static struct hash *zebra_l2_bridge_vlan_table_create(void) diff --git a/zebra/zebra_mpls.c b/zebra/zebra_mpls.c index 4c2d54612..4aaf6f25a 100644 --- a/zebra/zebra_mpls.c +++ b/zebra/zebra_mpls.c @@ -4058,10 +4058,8 @@ static void lsp_table_free(void *p) void zebra_mpls_close_tables(struct zebra_vrf *zvrf) { hash_iterate(zvrf->lsp_table, lsp_uninstall_from_kernel, NULL); - hash_clean(zvrf->lsp_table, lsp_table_free); - hash_free(zvrf->lsp_table); - hash_clean(zvrf->slsp_table, lsp_table_free); - hash_free(zvrf->slsp_table); + hash_clean_and_free(&zvrf->lsp_table, lsp_table_free); + hash_clean_and_free(&zvrf->slsp_table, lsp_table_free); route_table_finish(zvrf->fec_table[AFI_IP]); route_table_finish(zvrf->fec_table[AFI_IP6]); } diff --git a/zebra/zebra_router.c b/zebra/zebra_router.c index 21e09a81f..787442f5c 100644 --- a/zebra/zebra_router.c +++ b/zebra/zebra_router.c @@ -232,20 +232,15 @@ void zebra_router_terminate(void) /* Free NHE in ID table only since it has unhashable entries as well */ hash_iterate(zrouter.nhgs_id, zebra_nhg_hash_free_zero_id, NULL); - hash_clean(zrouter.nhgs_id, zebra_nhg_hash_free); - hash_free(zrouter.nhgs_id); - hash_clean(zrouter.nhgs, NULL); - hash_free(zrouter.nhgs); - - hash_clean(zrouter.rules_hash, zebra_pbr_rules_free); - hash_free(zrouter.rules_hash); - - hash_clean(zrouter.ipset_entry_hash, zebra_pbr_ipset_entry_free), - hash_clean(zrouter.ipset_hash, zebra_pbr_ipset_free); - hash_free(zrouter.ipset_hash); - hash_free(zrouter.ipset_entry_hash); - hash_clean(zrouter.iptable_hash, zebra_pbr_iptable_free); - hash_free(zrouter.iptable_hash); + hash_clean_and_free(&zrouter.nhgs_id, zebra_nhg_hash_free); + hash_clean_and_free(&zrouter.nhgs, NULL); + + hash_clean_and_free(&zrouter.rules_hash, zebra_pbr_rules_free); + + hash_clean_and_free(&zrouter.ipset_entry_hash, + zebra_pbr_ipset_entry_free); + hash_clean_and_free(&zrouter.ipset_hash, zebra_pbr_ipset_free); + hash_clean_and_free(&zrouter.iptable_hash, zebra_pbr_iptable_free); #ifdef HAVE_SCRIPTING zebra_script_destroy(); diff --git a/zebra/zebra_vxlan_if.c b/zebra/zebra_vxlan_if.c index 08e07b60a..3cc7e499b 100644 --- a/zebra/zebra_vxlan_if.c +++ b/zebra/zebra_vxlan_if.c @@ -610,10 +610,7 @@ struct hash *zebra_vxlan_vni_table_create(void) void zebra_vxlan_vni_table_destroy(struct hash *vni_table) { - if (vni_table) { - hash_clean(vni_table, zebra_vxlan_vni_free); - hash_free(vni_table); - } + hash_clean_and_free(&vni_table, zebra_vxlan_vni_free); } int zebra_vxlan_if_vni_table_destroy(struct zebra_if *zif) |