]> git.puffer.fish Git - mirror/frr.git/commitdiff
bgpd: Fixes for memory leaks. 6176/head
authorNaveen Thanikachalam <nthanikachal@vmware.com>
Tue, 7 Apr 2020 12:03:34 +0000 (05:03 -0700)
committerNaveen Thanikachalam <nthanikachal@vmware.com>
Thu, 9 Apr 2020 03:27:49 +0000 (20:27 -0700)
This commit addresses the memory leaks when certain BGP JSON
show commands are executed

Signed-off-by: NaveenThanikachalam <nthanikachal@vmware.com>
bgpd/bgp_lcommunity.c
bgpd/bgp_route.c
bgpd/bgp_vty.c

index ec7d07fe73bc7667d836509eea0f4325c385e7c2..f47ae91663ed5cd90a10226210558a055ff63c13 100644 (file)
@@ -46,6 +46,8 @@ void lcommunity_free(struct lcommunity **lcom)
 {
        XFREE(MTYPE_LCOMMUNITY_VAL, (*lcom)->val);
        XFREE(MTYPE_LCOMMUNITY_STR, (*lcom)->str);
+       if ((*lcom)->json)
+               json_object_free((*lcom)->json);
        XFREE(MTYPE_LCOMMUNITY, *lcom);
 }
 
index a11e1d7c693c2be0c141ac9a1bde7ff327452cc3..94e6cd27e2092afe3d93a7cd09ff42db953654a8 100644 (file)
@@ -11594,8 +11594,8 @@ static void show_adj_route(struct vty *vty, struct peer *peer, afi_t afi,
        struct bgp_table *table;
        struct bgp_adj_in *ain;
        struct bgp_adj_out *adj;
-       unsigned long output_count;
-       unsigned long filtered_count;
+       unsigned long output_count = 0;
+       unsigned long filtered_count = 0;
        struct bgp_node *rn;
        int header1 = 1;
        struct bgp *bgp;
@@ -11885,6 +11885,12 @@ static void show_adj_route(struct vty *vty, struct peer *peer, afi_t afi,
 
                vty_out(vty, "%s\n", json_object_to_json_string_ext(
                                             json, JSON_C_TO_STRING_PRETTY));
+
+               if (!output_count && !filtered_count) {
+                       json_object_free(json_scode);
+                       json_object_free(json_ocode);
+               }
+
                json_object_free(json);
        } else if (output_count > 0) {
                if (filtered_count > 0)
index bfa3ee92a0d9a5dbca2e96b377d70bb77392313e..8f06fdf86c2fba33b39197f24dbd08ef03e15391 100644 (file)
@@ -12192,14 +12192,20 @@ static int bgp_show_neighbor_graceful_restart(struct vty *vty, struct bgp *bgp,
                                              enum show_type type,
                                              union sockunion *su,
                                              const char *conf_if, afi_t afi,
-                                             bool use_json, json_object *json)
+                                             bool use_json)
 {
        struct listnode *node, *nnode;
        struct peer *peer;
        int find = 0;
        safi_t safi = SAFI_UNICAST;
+       json_object *json = NULL;
        json_object *json_neighbor = NULL;
 
+       if (use_json) {
+               json = json_object_new_object();
+               json_neighbor = json_object_new_object();
+       }
+
        for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
 
                if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
@@ -12208,16 +12214,15 @@ static int bgp_show_neighbor_graceful_restart(struct vty *vty, struct bgp *bgp,
                if ((peer->afc[afi][safi]) == 0)
                        continue;
 
-               if (use_json)
-                       json_neighbor = json_object_new_object();
-
                if (type == show_all) {
                        bgp_show_peer_gr_status(vty, peer, use_json,
                                                json_neighbor);
 
-                       if (use_json)
+                       if (use_json) {
                                json_object_object_add(json, peer->host,
                                                       json_neighbor);
+                               json_neighbor = NULL;
+                       }
 
                } else if (type == show_peer) {
                        if (conf_if) {
@@ -12243,8 +12248,10 @@ static int bgp_show_neighbor_graceful_restart(struct vty *vty, struct bgp *bgp,
                                                       json_neighbor);
                }
 
-               if (find)
+               if (find) {
+                       json_neighbor = NULL;
                        break;
+               }
        }
 
        if (type == show_peer && !find) {
@@ -12257,6 +12264,10 @@ static int bgp_show_neighbor_graceful_restart(struct vty *vty, struct bgp *bgp,
                vty_out(vty, "%s\n",
                        json_object_to_json_string_ext(
                                json, JSON_C_TO_STRING_PRETTY));
+
+               if (json_neighbor)
+                       json_object_free(json_neighbor);
+               json_object_free(json);
        } else {
                vty_out(vty, "\n");
        }
@@ -12378,7 +12389,6 @@ static void bgp_show_neighbor_graceful_restart_vty(struct vty *vty,
        int ret;
        struct bgp *bgp;
        union sockunion su;
-       json_object *json = NULL;
 
        bgp = bgp_get_default();
 
@@ -12389,20 +12399,17 @@ static void bgp_show_neighbor_graceful_restart_vty(struct vty *vty,
                bgp_show_global_graceful_restart_mode_vty(vty, bgp, use_json,
                                                          NULL);
 
-       json = json_object_new_object();
        if (ip_str) {
                ret = str2sockunion(ip_str, &su);
                if (ret < 0)
-                       bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL,
-                                                          ip_str, afi,
-                                                          use_json, json);
-               else
                        bgp_show_neighbor_graceful_restart(
-                               vty, bgp, type, &su, NULL, afi, use_json, json);
+                               vty, bgp, type, NULL, ip_str, afi, use_json);
+               else
+                       bgp_show_neighbor_graceful_restart(vty, bgp, type, &su,
+                                                          NULL, afi, use_json);
        } else
                bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL, NULL,
-                                                  afi, use_json, json);
-       json_object_free(json);
+                                                  afi, use_json);
 }
 
 static void bgp_show_all_instances_neighbors_vty(struct vty *vty,