]> git.puffer.fish Git - matthieu/frr.git/commitdiff
bgpd: Check for NULL inside aspath_unintern()
authorDonatas Abraitis <donatas.abraitis@gmail.com>
Wed, 9 Feb 2022 14:41:14 +0000 (16:41 +0200)
committerDonatas Abraitis <donatas.abraitis@gmail.com>
Wed, 9 Feb 2022 14:41:14 +0000 (16:41 +0200)
It's not always guarded, just check inside.

Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
bgpd/bgp_aspath.c
bgpd/bgp_attr.c
tests/bgpd/test_aspath.c

index 192cd6ca82fc14ca02bce215b70e7686b99c3612..dd27c9f6a12ff0683eadceb32861008266d74962 100644 (file)
@@ -328,7 +328,12 @@ void aspath_free(struct aspath *aspath)
 void aspath_unintern(struct aspath **aspath)
 {
        struct aspath *ret;
-       struct aspath *asp = *aspath;
+       struct aspath *asp;
+
+       if (!*aspath)
+               return;
+
+       asp = *aspath;
 
        if (asp->refcnt)
                asp->refcnt--;
index 3c3fd174f66b5892a5e0880a6f51ccfaa70d95e0..607e5152b5d5734d642457ce7e6e54c17e70665f 100644 (file)
@@ -1093,8 +1093,7 @@ void bgp_attr_unintern_sub(struct attr *attr)
        struct cluster_list *cluster;
 
        /* aspath refcount shoud be decrement. */
-       if (attr->aspath)
-               aspath_unintern(&attr->aspath);
+       aspath_unintern(&attr->aspath);
        UNSET_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_AS_PATH));
 
        if (attr->community)
@@ -3534,14 +3533,12 @@ done:
         * we can chuck as4_aggregator and as4_path alltogether in order
         * to save memory
         */
-       if (as4_path) {
-               /*
-                * unintern - it is in the hash
-                * The flag that we got this is still there, but that
-                * does not do any trouble
-                */
-               aspath_unintern(&as4_path);
-       }
+       /*
+        * unintern - it is in the hash
+        * The flag that we got this is still there, but that
+        * does not do any trouble
+        */
+       aspath_unintern(&as4_path);
 
        transit = bgp_attr_get_transit(attr);
        if (ret != BGP_ATTR_PARSE_ERROR) {
index c2d39752ab4099fed1c01792ddcc90f12945c911..7288dc08696b453f8da17158f144b18f8bc1d1dc 100644 (file)
@@ -1062,8 +1062,7 @@ static void parse_test(struct test_segment *t)
 
        printf("\n");
 
-       if (asp)
-               aspath_unintern(&asp);
+       aspath_unintern(&asp);
 }
 
 /* prepend testing */
@@ -1117,8 +1116,7 @@ static void empty_prepend_test(struct test_segment *t)
                printf(FAILED "!\n");
 
        printf("\n");
-       if (asp1)
-               aspath_unintern(&asp1);
+       aspath_unintern(&asp1);
        aspath_free(asp2);
 }
 
@@ -1277,10 +1275,8 @@ static int handle_attr_test(struct aspath_tests *t)
        }
 
 out:
-       if (attr.aspath)
-               aspath_unintern(&attr.aspath);
-       if (asp)
-               aspath_unintern(&asp);
+       aspath_unintern(&attr.aspath);
+       aspath_unintern(&asp);
        return failed - initfail;
 }