summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDonald Sharp <sharpd@cumulusnetworks.com>2018-06-12 10:38:37 -0400
committerDonald Sharp <sharpd@cumulusnetworks.com>2018-06-12 15:12:48 -0400
commitc93a3b77e66ae60d618297eadb6319c519a22ee4 (patch)
treece7961bb94de770d1067062d20d6e38b8b945f9c
parentefb02f8814049664caa7a824652defcfb3b4f2b1 (diff)
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 <sharpd@cumulusnetworks.com>
-rw-r--r--bgpd/bgp_route.c43
1 files changed, 21 insertions, 22 deletions
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);