From 3e7b3ed1dc4dd37120b4bb791790792ac484f5ef Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Fri, 5 May 2023 19:03:40 -0400 Subject: [PATCH] zebra: dplane_gre_set could return while leaking ctx Prevent this function from leaking the ctx memory. Also properly record that something has gone wrong. Signed-off-by: Donald Sharp --- zebra/zebra_dplane.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/zebra/zebra_dplane.c b/zebra/zebra_dplane.c index e78cd3b1d0..a3b61c9049 100644 --- a/zebra/zebra_dplane.c +++ b/zebra/zebra_dplane.c @@ -5303,8 +5303,10 @@ dplane_gre_set(struct interface *ifp, struct interface *ifp_link, ctx = dplane_ctx_alloc(); - if (!ifp) - return result; + if (!ifp) { + ret = EINVAL; + goto done; + } if (IS_ZEBRA_DEBUG_DPLANE_DETAIL) { zlog_debug("init dplane ctx %s: if %s link %s%s", @@ -5316,8 +5318,11 @@ dplane_gre_set(struct interface *ifp, struct interface *ifp_link, ctx->zd_op = op; ctx->zd_status = ZEBRA_DPLANE_REQUEST_SUCCESS; zns = zebra_ns_lookup(ifp->vrf->vrf_id); - if (!zns) - return result; + if (!zns) { + ret = EINVAL; + goto done; + } + dplane_ctx_ns_init(ctx, zns, false); dplane_ctx_set_ifname(ctx, ifp->name); @@ -5336,6 +5341,7 @@ dplane_gre_set(struct interface *ifp, struct interface *ifp_link, /* Enqueue context for processing */ ret = dplane_update_enqueue(ctx); +done: /* Update counter */ atomic_fetch_add_explicit(&zdplane_info.dg_gre_set_in, 1, memory_order_relaxed); -- 2.39.5