Skip to content

Commit

Permalink
bgpd: Avoid unnecessary creation and free of json object
Browse files Browse the repository at this point in the history
In peer_adj_routes_brief(), the 'json' variable is only used for early
exit i.e. during early warning conditions. No point in creating and
freeing the json object everytime during non early exit cases (Majority
of the times)

Ticket :#4081784

Signed-off-by: Rajasekar Raja <[email protected]>
  • Loading branch information
raja-rajasekar authored and donaldsharp committed Dec 18, 2024
1 parent b3091c2 commit 47a3e7b
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion bgpd/bgp_route.c
Original file line number Diff line number Diff line change
Expand Up @@ -14485,15 +14485,16 @@ static int peer_adj_routes_brief(struct vty *vty, struct peer *peer, afi_t afi,
json_object *json_prefix = NULL; /* JSON per prefix */
struct bgp_dest *dest;

json = json_object_new_object();
if (!peer || !peer->afc[afi][safi]) {
json = json_object_new_object();
json_object_string_add(json, "warning", "No such neighbor or address family");
vty_out(vty, "%s\n", json_object_to_json_string(json));
json_object_free(json);
return CMD_WARNING;
}
if ((type == bgp_show_adj_route_received || type == bgp_show_adj_route_filtered) &&
!CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)) {
json = json_object_new_object();
json_object_string_add(json, "warning", "Inbound soft reconfiguration not enabled");
vty_out(vty, "%s\n", json_object_to_json_string(json));
json_object_free(json);
Expand Down

0 comments on commit 47a3e7b

Please sign in to comment.