Commit 3cd1a47f4c for frr
commit 3cd1a47f4c9174f29101cd0420084bd4bf36365f
Author: Mark Stapp <mjs@cisco.com>
Date: Thu Oct 22 13:38:26 2026 -0400
lib: clear hash efficiently when freeing route table
We have a more efficient "clear out the hashtable" api; use
that when freeing a route table instead of removing nodes one
at a time.
Signed-off-by: Mark Stapp <mjs@cisco.com>
diff --git a/lib/table.c b/lib/table.c
index 121f85c57c..f75a7c3455 100644
--- a/lib/table.c
+++ b/lib/table.c
@@ -106,15 +106,20 @@ static void route_table_free(struct route_table *rt)
{
struct route_node *tmp_node;
struct route_node *node;
+ uint32_t idx = 0;
if (rt == NULL)
return;
+ /* Clear the hashtable */
+ do {
+ node = rn_hash_node_pop_all(&rt->hash, &idx);
+ } while (node != NULL);
+
/* Handling for non-LPM tables, where there is no 'tree' */
if (rt->unique_mode) {
while ((node = rn_tree_pop(&rt->tree)) != NULL) {
node->lock = 0; /* to cause assert if unlocked after this */
- rn_hash_node_del(&rt->hash, node);
route_node_free(rt, node);
rt->count--;
}
@@ -145,7 +150,6 @@ static void route_table_free(struct route_table *rt)
tmp_node->table->count--;
tmp_node->lock =
0; /* to cause assert if unlocked after this */
- rn_hash_node_del(&rt->hash, tmp_node);
route_node_free(rt, tmp_node);
if (node != NULL) {