]> git.puffer.fish Git - matthieu/frr.git/commitdiff
bgpd: Move extra free code and fix a bug.
authorDonald Sharp <sharpd@cumulusnetworks.com>
Tue, 12 Jun 2018 14:38:37 +0000 (10:38 -0400)
committerDonald Sharp <sharpd@cumulusnetworks.com>
Tue, 12 Jun 2018 19:12:48 +0000 (15:12 -0400)
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>
bgpd/bgp_route.c

index d3c03cb72213cd6cdb527ebe01f4d81b70bc3b12..11223336e0b13d4045d9619bbc6fea040b359670 100644 (file)
@@ -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);