]> git.proxmox.com Git - mirror_frr.git/commitdiff
bgpd: fix memory leak in evpn json outpus II
authorChirag Shah <chirag@cumulusnetworks.com>
Mon, 27 Jan 2020 18:41:22 +0000 (10:41 -0800)
committerChirag Shah <chirag@cumulusnetworks.com>
Mon, 27 Jan 2020 19:07:02 +0000 (11:07 -0800)
Two of the evpn show commands with json option has memory leak.
1) show bgp l2vpn evpn route vni all json
2) show bgp l2vpn evpn route esi json

Before fix:
----------
Executed 'show bgp l2vpn evpn route vni all json' multiple times
used ordinary blocks continue to increase.

Note at the time of show command capture there were 22 evpn routes
in vni evpn route table.

Memory statistics for bgpd:
System allocator statistics:
  Total heap allocated:  9152 KiB
  Holding block headers: 0 bytes
  Used small blocks:     0 bytes
  Used ordinary blocks:  7300 KiB
  Free small blocks:     1760 bytes
  Free ordinary blocks:  1852 KiB
  Ordinary blocks:       880
  Small blocks:          51
  Holding blocks:        0

Ticket:CM-27920
Reviewed By:
Testing Done:

After fix:
---------
Executed 'show bgp l2vpn evpn route vni all json' multiple times
Used ordinary blocks remains low.

Memory statistics for bgpd:
System allocator statistics:
  Total heap allocated:  8356 KiB
  Holding block headers: 0 bytes
  Used small blocks:     0 bytes
  Used ordinary blocks:  6492 KiB
  Free small blocks:     1840 bytes
  Free ordinary blocks:  1864 KiB
  Ordinary blocks:       939
  Small blocks:          52
  Holding blocks:        0

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

index 125ed61e74664f99271ca03cad107a314944cbce..44a884830a7a07d2627d493463168636cabcbf01 100644 (file)
@@ -687,14 +687,22 @@ static void show_esi_routes(struct bgp *bgp,
                        add_prefix_to_json = 1;
                }
 
-               if (json && add_prefix_to_json) {
-                       json_object_string_add(json_prefix, "prefix",
-                                              prefix_str);
-                       json_object_int_add(json_prefix, "prefixLen",
-                                           rn->p.prefixlen);
-                       json_object_object_add(json_prefix, "paths",
-                                              json_paths);
-                       json_object_object_add(json, prefix_str, json_prefix);
+               if (json) {
+                       if (add_prefix_to_json) {
+                               json_object_string_add(json_prefix, "prefix",
+                                                      prefix_str);
+                               json_object_int_add(json_prefix, "prefixLen",
+                                                   rn->p.prefixlen);
+                               json_object_object_add(json_prefix, "paths",
+                                                      json_paths);
+                               json_object_object_add(json, prefix_str,
+                                                      json_prefix);
+                       } else {
+                               json_object_free(json_paths);
+                               json_object_free(json_prefix);
+                               json_paths = NULL;
+                               json_prefix = NULL;
+                       }
                }
        }
 
@@ -786,14 +794,22 @@ static void show_vni_routes(struct bgp *bgp, struct bgpevpn *vpn, int type,
                        add_prefix_to_json = 1;
                }
 
-               if (json && add_prefix_to_json) {
-                       json_object_string_add(json_prefix, "prefix",
-                                              prefix_str);
-                       json_object_int_add(json_prefix, "prefixLen",
-                                           rn->p.prefixlen);
-                       json_object_object_add(json_prefix, "paths",
-                                              json_paths);
-                       json_object_object_add(json, prefix_str, json_prefix);
+               if (json) {
+                       if (add_prefix_to_json) {
+                               json_object_string_add(json_prefix, "prefix",
+                                                      prefix_str);
+                               json_object_int_add(json_prefix, "prefixLen",
+                                                   rn->p.prefixlen);
+                               json_object_object_add(json_prefix, "paths",
+                                                      json_paths);
+                               json_object_object_add(json, prefix_str,
+                                                      json_prefix);
+                       } else {
+                               json_object_free(json_paths);
+                               json_object_free(json_prefix);
+                               json_paths = NULL;
+                               json_prefix = NULL;
+                       }
                }
        }