Commit 98f8e9472e for frr
commit 98f8e9472e4408eb8af97c25fc0ea6dd24fbe385
Author: Nageswara Soma <nsoma@cisco.com>
Date: Mon Jun 15 12:30:21 2026 -0700
zebra: free early route wrapper on enqueue failure
If the RIB work queue is absent, release the rejected
early-route wrapper. Keep ownership of the route entry
and temporary NHE with the callers on failure, and
free both there to avoid leaking the NHE copy.
For rib_delete(), free the entire rejected request
because the function allocates all of its objects.
Signed-off-by: Nageswara Soma <nsoma@cisco.com>
diff --git a/zebra/zapi_msg.c b/zebra/zapi_msg.c
index aa4aaa63b0..408cc5aef3 100644
--- a/zebra/zapi_msg.c
+++ b/zebra/zapi_msg.c
@@ -2273,6 +2273,8 @@ static void zread_route_add(ZAPI_HANDLER_ARGS)
*/
if (ret == -1) {
client->error_cnt++;
+ if (n)
+ zebra_nhg_free(n);
zebra_rib_route_entry_free(re);
}
diff --git a/zebra/zebra_rib.c b/zebra/zebra_rib.c
index cd75ea3e39..a07f83a0e8 100644
--- a/zebra/zebra_rib.c
+++ b/zebra/zebra_rib.c
@@ -4524,6 +4524,7 @@ int rib_add_multipath_nhe(afi_t afi, safi_t safi, struct prefix *p, struct prefi
bool replace)
{
struct zebra_early_route *ere;
+ int ret;
if (!re)
return -1;
@@ -4542,7 +4543,11 @@ int rib_add_multipath_nhe(afi_t afi, safi_t safi, struct prefix *p, struct prefi
ere->startup = startup;
ere->replace = replace;
- return mq_add_handler(ere, rib_meta_queue_early_route_add);
+ ret = mq_add_handler(ere, rib_meta_queue_early_route_add);
+ if (ret == -1)
+ XFREE(MTYPE_WQ_WRAPPER, ere);
+
+ return ret;
}
/*
@@ -4631,8 +4636,10 @@ int rib_add_multipath(afi_t afi, safi_t safi, struct prefix *p, struct prefix_ip
ret = rib_add_multipath_nhe(afi, safi, p, src_p, re, n, startup, replace);
/* In error cases, free the route also */
- if (ret < 0)
+ if (ret < 0) {
+ zebra_nhg_free(n);
zebra_rib_route_entry_free(re);
+ }
return ret;
}
@@ -4668,7 +4675,8 @@ void rib_delete(afi_t afi, safi_t safi, vrf_id_t vrf_id, int type,
ere->deletion = true;
ere->fromkernel = fromkernel;
- mq_add_handler(ere, rib_meta_queue_early_route_add);
+ if (mq_add_handler(ere, rib_meta_queue_early_route_add) == -1)
+ early_route_memory_free(ere);
}