From 121067e9c598f44f62bf9e11774fd100ca5ce8a9 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Tue, 18 Aug 2020 13:54:03 -0400 Subject: [PATCH] bgpd: Prevent crash when displaying json of a vrf all command When iterating over a `show ip bgp vrf all neighbors json` command bgp is crashing. The json variable was being double freed. When freeing it, set it to NULL and then check to make sure it exists before we free. Signed-off-by: Donald Sharp --- bgpd/bgp_vty.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c index b2a795b97d..af02e13340 100644 --- a/bgpd/bgp_vty.c +++ b/bgpd/bgp_vty.c @@ -12746,11 +12746,13 @@ static void bgp_show_all_instances_neighbors_vty(struct vty *vty, use_json, json); } json_object_free(json); + json = NULL; } if (use_json) { vty_out(vty, "}\n"); - json_object_free(json); + if (json) + json_object_free(json); } else if (!nbr_output) vty_out(vty, "%% BGP instance not found\n");