]> git.proxmox.com Git - mirror_frr.git/commitdiff
bgpd: fix memory leak in evpn json outputs
authorChirag Shah <chirag@cumulusnetworks.com>
Wed, 22 Jan 2020 20:22:27 +0000 (12:22 -0800)
committerChirag Shah <chirag@cumulusnetworks.com>
Fri, 24 Jan 2020 20:17:17 +0000 (12:17 -0800)
Found memory leak in json output of evpn's route
commands.

After executing 'show bgp l2vpn evpn route type prefix json'
and 'show bgp l2vpn evpn route type macip json' few times
(6 times) with more than 600 routes in total seeing
memory footprint for bgpd continue to grow.

Memory statistics for bgpd:
System allocator statistics:
  Total heap allocated:  12 MiB
  Holding block headers: 0 bytes
  Used small blocks:     0 bytes
  Used ordinary blocks:  8390 KiB
  Free small blocks:     1760 bytes
  Free ordinary blocks:  3762 KiB
  Ordinary blocks:       1161
  Small blocks:          51
  Holding blocks:        0

Ticket:CM-27920
Testing Done:

After fix:
excute few times,
'show bgp l2vpn evpn route type prefix json'
and 'show bgp l2vpn evpn route type macip json'
commands where used ordinary blocks (uordblks) is
in steady state.

Memory statistics for bgpd:
System allocator statistics:
  Total heap allocated:  9968 KiB
  Holding block headers: 0 bytes
  Used small blocks:     0 bytes
  Used ordinary blocks:  6486 KiB
  Free small blocks:     1984 bytes
  Free ordinary blocks:  3482 KiB
  Ordinary blocks:       1110
  Small blocks:          54
  Holding blocks:        0

Memory statistics for bgpd:
System allocator statistics:
  Total heap allocated:  10100 KiB
  Holding block headers: 0 bytes
  Used small blocks:     0 bytes
  Used ordinary blocks:  6488 KiB
  Free small blocks:     1984 bytes
  Free ordinary blocks:  3612 KiB
  Ordinary blocks:       1113
  Small blocks:          54
  Holding blocks:        0

Signed-off-by: Chirag Shah <chirag@cumulusnetworks.com>
bgpd/bgp_evpn_vty.c

index 3049a00ce3205822958d66b8738de902c7e547c2..125ed61e74664f99271ca03cad107a314944cbce 100644 (file)
@@ -2579,18 +2579,29 @@ static void evpn_show_route_rd(struct vty *vty, struct bgp *bgp,
                        add_rd_to_json = 1;
                }
 
-               if (json && add_prefix_to_json) {
-                       json_object_object_add(json_prefix, "paths",
-                                              json_paths);
-                       json_object_object_add(json_rd, prefix_str,
-                                              json_prefix);
+               if (json) {
+                       if (add_prefix_to_json) {
+                               json_object_object_add(json_prefix, "paths",
+                                                      json_paths);
+                               json_object_object_add(json_rd, prefix_str,
+                                                      json_prefix);
+                       } else {
+                               json_object_free(json_paths);
+                               json_object_free(json_prefix);
+                               json_paths = NULL;
+                               json_prefix = NULL;
+                       }
                }
        }
 
-       if (json && add_rd_to_json)
-               json_object_object_add(json, rd_str, json_rd);
-
        if (json) {
+               if (add_rd_to_json)
+                       json_object_object_add(json, rd_str, json_rd);
+               else {
+                       json_object_free(json_rd);
+                       json_rd = NULL;
+               }
+
                json_object_int_add(json, "numPrefix", prefix_cnt);
                json_object_int_add(json, "numPaths", path_cnt);
        } else {
@@ -2732,16 +2743,31 @@ static void evpn_show_all_routes(struct vty *vty, struct bgp *bgp, int type,
                                                              json_path);
                        }
 
-                       if (json && add_prefix_to_json) {
-                               json_object_object_add(json_prefix, "paths",
-                                                      json_paths);
-                               json_object_object_add(json_rd, prefix_str,
-                                                      json_prefix);
+                       if (json) {
+                               if (add_prefix_to_json) {
+                                       json_object_object_add(json_prefix,
+                                                              "paths",
+                                                              json_paths);
+                                       json_object_object_add(json_rd,
+                                                              prefix_str,
+                                                              json_prefix);
+                               } else {
+                                       json_object_free(json_prefix);
+                                       json_object_free(json_paths);
+                                       json_prefix = NULL;
+                                       json_paths = NULL;
+                               }
                        }
                }
 
-               if (json && add_rd_to_json)
-                       json_object_object_add(json, rd_str, json_rd);
+               if (json) {
+                       if (add_rd_to_json)
+                               json_object_object_add(json, rd_str, json_rd);
+                       else {
+                               json_object_free(json_rd);
+                               json_rd = NULL;
+                       }
+               }
        }
 
        if (json) {