]> git.puffer.fish Git - matthieu/frr.git/commitdiff
bgpd: resolve memleak on show bgp vrf all ipv6 unicast summary json
authorDon Slice <dslice@cumulusnetworks.com>
Wed, 31 Jul 2019 16:38:49 +0000 (12:38 -0400)
committerDon Slice <dslice@cumulusnetworks.com>
Fri, 2 Aug 2019 11:50:46 +0000 (04:50 -0700)
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>
bgpd/bgp_vty.c

index 27042017dd7ff343562e9ff46216e6aef692905d..6974594ab5c44f1afdefefd203b3a4545909cf35 100644 (file)
@@ -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");