From: Donald Sharp Date: Wed, 14 Dec 2022 21:31:37 +0000 (-0500) Subject: bgpd: If we don't find what we are looking for cleanup the json structure X-Git-Tag: base_8.5~135^2 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=5a59e9b21fa93f706f7b5887820449fffab8e375;p=matthieu%2Ffrr.git bgpd: If we don't find what we are looking for cleanup the json structure Signed-off-by: Donald Sharp --- diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c index 219362cd04..8ea9c1996b 100644 --- a/bgpd/bgp_vty.c +++ b/bgpd/bgp_vty.c @@ -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