From: Chirag Shah Date: Mon, 27 Jan 2020 18:41:22 +0000 (-0800) Subject: bgpd: fix memory leak in evpn json outpus II X-Git-Tag: frr-7.3~4^2 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=0028b683ef3b22298be2a310895873ddfe3f11e1;p=mirror%2Ffrr.git bgpd: fix memory leak in evpn json outpus II 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 --- diff --git a/bgpd/bgp_evpn_vty.c b/bgpd/bgp_evpn_vty.c index 125ed61e74..44a884830a 100644 --- a/bgpd/bgp_evpn_vty.c +++ b/bgpd/bgp_evpn_vty.c @@ -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; + } } }