From 66c28560bac4035a92ea992f531b1d8e5250fab7 Mon Sep 17 00:00:00 2001 From: Stephen Worley Date: Mon, 28 Sep 2020 12:39:22 -0400 Subject: [PATCH] zebra: set NHG/backup NHG pointers on success zapi read Only set the NHG/backup NHG pointers of the caller if the read of the nexthops was successfull. Otherwise, we might free when not neccessary or double free. Signed-off-by: Stephen Worley --- zebra/zapi_msg.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/zebra/zapi_msg.c b/zebra/zapi_msg.c index 1d8c5c7cc0..c33bca3d86 100644 --- a/zebra/zapi_msg.c +++ b/zebra/zapi_msg.c @@ -1622,14 +1622,14 @@ static bool zapi_read_nexthops(struct zserv *client, struct prefix *p, assert(!(png && pbnhg)); if (png) - *png = ng = nexthop_group_new(); + ng = nexthop_group_new(); if (pbnhg && backup_nh_num > 0) { if (IS_ZEBRA_DEBUG_RECV) zlog_debug("%s: adding %d backup nexthops", __func__, backup_nh_num); - *pbnhg = bnhg = zebra_nhg_backup_alloc(); + bnhg = zebra_nhg_backup_alloc(); } /* @@ -1704,7 +1704,7 @@ static bool zapi_read_nexthops(struct zserv *client, struct prefix *p, __func__, nhbuf, api_nh->vrf_id, labelbuf); } - if (png) { + if (ng) { /* Add new nexthop to temporary list. This list is * canonicalized - sorted - so that it can be hashed * later in route processing. We expect that the sender @@ -1729,6 +1729,14 @@ static bool zapi_read_nexthops(struct zserv *client, struct prefix *p, } } + + /* succesfully read, set caller pointers now */ + if (png) + *png = ng; + + if (pbnhg) + *pbnhg = bnhg; + return true; } @@ -1847,9 +1855,6 @@ static void zread_nhg_add(ZAPI_HANDLER_ARGS) flog_warn(EC_ZEBRA_NEXTHOP_CREATION_FAILED, "%s: Nexthop Group Creation failed", __func__); - - nexthop_group_delete(&nhg); - zebra_nhg_backup_free(&bnhg); return; } -- 2.39.5