summaryrefslogtreecommitdiffstats
path: root/bgpd
diff options
context:
space:
mode:
authorDon Slice <dslice@cumulusnetworks.com>2019-07-31 18:38:49 +0200
committerDon Slice <dslice@cumulusnetworks.com>2019-08-02 13:50:46 +0200
commitf86897b945bdb840db85d26ce4bc38b469ca4da6 (patch)
treea24fab89709234357451fb814f8447a64daacd98 /bgpd
parentMerge pull request #4766 from donaldsharp/redist_small_fix (diff)
downloadfrr-f86897b945bdb840db85d26ce4bc38b469ca4da6.tar.xz
frr-f86897b945bdb840db85d26ce4bc38b469ca4da6.zip
bgpd: resolve memleak on show bgp vrf all ipv6 unicast summary json
Problem reported with memory leak when the command "show bgp vrf all ipv6 unicast summary json" is issued. Found that the problem only occurs if the configuration does not actually include the ipv6 address-family but does contain ipv4 unicast peers. If we didn't match a peer in the address-family being displayed, we would create the json object but never free it. This fix actually stops creating the json object in this section of code and lets the create happen in the area where the match occurs. Ticket: CM-25616 Signed-off-by: Don Slice <dslice@cumulusnetworks.com>
Diffstat (limited to 'bgpd')
-rw-r--r--bgpd/bgp_vty.c21
1 files changed, 10 insertions, 11 deletions
diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c
index 27042017d..6974594ab 100644
--- a/bgpd/bgp_vty.c
+++ b/bgpd/bgp_vty.c
@@ -8202,14 +8202,14 @@ static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
}
static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
- int safi, bool use_json,
- json_object *json)
+ int safi, bool use_json)
{
int is_first = 1;
int afi_wildcard = (afi == AFI_MAX);
int safi_wildcard = (safi == SAFI_MAX);
int is_wildcard = (afi_wildcard || safi_wildcard);
bool nbr_output = false;
+ json_object *json = NULL;
if (use_json && is_wildcard)
vty_out(vty, "{\n");
@@ -8221,6 +8221,10 @@ static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
while (safi < SAFI_MAX) {
if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
nbr_output = true;
+
+ if (use_json)
+ json = json_object_new_object();
+
if (is_wildcard) {
/*
* So limit output to those afi/safi
@@ -8229,8 +8233,6 @@ static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
* them
*/
if (use_json) {
- json = json_object_new_object();
-
if (!is_first)
vty_out(vty, ",\n");
else
@@ -8272,7 +8274,6 @@ static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
{
struct listnode *node, *nnode;
struct bgp *bgp;
- json_object *json = NULL;
int is_first = 1;
bool nbr_output = false;
@@ -8282,8 +8283,6 @@ static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
nbr_output = true;
if (use_json) {
- json = json_object_new_object();
-
if (!is_first)
vty_out(vty, ",\n");
else
@@ -8299,7 +8298,7 @@ static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
? VRF_DEFAULT_NAME
: bgp->name);
}
- bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, json);
+ bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json);
}
if (use_json)
@@ -8330,8 +8329,8 @@ int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
return CMD_WARNING;
}
- bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json,
- NULL);
+ bgp_show_summary_afi_safi(vty, bgp, afi, safi,
+ use_json);
return CMD_SUCCESS;
}
}
@@ -8339,7 +8338,7 @@ int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
bgp = bgp_get_default();
if (bgp)
- bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, NULL);
+ bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json);
else {
if (use_json)
vty_out(vty, "{}\n");