]> git.puffer.fish Git - matthieu/frr.git/commitdiff
bgpd: If we don't find what we are looking for cleanup the json structure
authorDonald Sharp <sharpd@nvidia.com>
Wed, 14 Dec 2022 21:31:37 +0000 (16:31 -0500)
committerDonald Sharp <sharpd@nvidia.com>
Thu, 15 Dec 2022 16:15:33 +0000 (11:15 -0500)
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
bgpd/bgp_vty.c

index 219362cd04316ffe239e6559057e8295b6c55d13..8ea9c1996bc61ff31e69122969f99c2f0f7d80f6 100644 (file)
@@ -14693,7 +14693,7 @@ static int bgp_show_neighbor_graceful_restart(struct vty *vty, struct bgp *bgp,
 {
        struct listnode *node, *nnode;
        struct peer *peer;
-       int find = 0;
+       bool found = false;
        safi_t safi = SAFI_UNICAST;
        json_object *json_neighbor = NULL;
 
@@ -14721,27 +14721,31 @@ static int bgp_show_neighbor_graceful_restart(struct vty *vty, struct bgp *bgp,
                                     && !strcmp(peer->conf_if, conf_if))
                                    || (peer->hostname
                                        && !strcmp(peer->hostname, conf_if))) {
-                                       find = 1;
+                                       found = true;
                                        bgp_show_peer_gr_status(vty, peer,
                                                                json_neighbor);
                                }
                        } else {
                                if (sockunion_same(&peer->su, su)) {
-                                       find = 1;
+                                       found = true;
                                        bgp_show_peer_gr_status(vty, peer,
                                                                json_neighbor);
                                }
                        }
-                       if (json && find)
-                               json_object_object_add(json, peer->host,
-                                                      json_neighbor);
+                       if (json) {
+                               if (found)
+                                       json_object_object_add(json, peer->host,
+                                                              json_neighbor);
+                               else
+                                       json_object_free(json_neighbor);
+                       }
                }
 
-               if (find)
+               if (found)
                        break;
        }
 
-       if (type == show_peer && !find) {
+       if (type == show_peer && !found) {
                if (json)
                        json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
                else