From: Donald Sharp Date: Tue, 12 Jun 2018 14:38:37 +0000 (-0400) Subject: bgpd: Move extra free code and fix a bug. X-Git-Tag: frr-6.1-dev~338^2~3 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=c93a3b77e66ae60d618297eadb6319c519a22ee4;p=mirror%2Ffrr.git bgpd: Move extra free code and fix a bug. The bgp_info_extra_free code was the correct place to free up data associated with the bgp_info pointer when we are deleting the bgp_info node. Additionally, if we have a parent pointer, we may not have a net pointer. So make sure we do. Finally clean up the bgp_info_extra_free code so it is a bit easier to read. Use variables instead of multiple level of casting. Signed-off-by: Donald Sharp --- diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index d3c03cb722..11223336e0 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -174,16 +174,31 @@ static struct bgp_info_extra *bgp_info_extra_new(void) static void bgp_info_extra_free(struct bgp_info_extra **extra) { - if (extra && *extra) { - if ((*extra)->damp_info) - bgp_damp_info_free((*extra)->damp_info, 0); + struct bgp_info_extra *e; - (*extra)->damp_info = NULL; + if (!extra || !*extra) + return; + + e = *extra; + if (e->damp_info) + bgp_damp_info_free(e->damp_info, 0); - XFREE(MTYPE_BGP_ROUTE_EXTRA, *extra); + e->damp_info = NULL; + if (e->parent) { + struct bgp_info *bi = (struct bgp_info *)e->parent; - *extra = NULL; + if (bi->net) + bgp_unlock_node((struct bgp_node *)bi->net); + bi->net = NULL; + bgp_info_unlock(e->parent); + e->parent = NULL; } + + if (e->bgp_orig) + bgp_unlock(e->bgp_orig); + XFREE(MTYPE_BGP_ROUTE_EXTRA, *extra); + + *extra = NULL; } /* Get bgp_info extra information for the given bgp_info, lazy allocated @@ -205,22 +220,6 @@ struct bgp_info *bgp_info_new(void) /* Free bgp route information. */ static void bgp_info_free(struct bgp_info *binfo) { - /* unlink reference to parent, if any. */ - if (binfo->extra) { - if (binfo->extra->parent) { - bgp_unlock_node( - (struct bgp_node *)((struct bgp_info *)binfo - ->extra->parent) - ->net); - bgp_info_unlock( - (struct bgp_info *)binfo->extra->parent); - binfo->extra->parent = NULL; - } - - if (binfo->extra->bgp_orig) - bgp_unlock(binfo->extra->bgp_orig); - } - if (binfo->attr) bgp_attr_unintern(&binfo->attr);