From b6175e0ca2a741e2efcf44422e014b0678cf0865 Mon Sep 17 00:00:00 2001 From: Christian Franke Date: Tue, 14 Jun 2016 20:07:01 +0200 Subject: [PATCH] bgpd: fix memory leaks in show commands sockunion_str2su allocates a struct sockunion that used to be leaked in the show commands. Use str2sockunion and keep the information on the stack instead. Signed-off-by: Christian Franke Signed-off-by: Christian Franke Acked-by: Donald Sharp Signed-off-by: Philippe Guibert --- bgpd/bgp_encap.c | 38 +++++++++++++++++--------------------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/bgpd/bgp_encap.c b/bgpd/bgp_encap.c index ac99169e7f..c60b592133 100644 --- a/bgpd/bgp_encap.c +++ b/bgpd/bgp_encap.c @@ -620,24 +620,23 @@ DEFUN (show_bgp_ipv4_encap_neighbor_routes, "Neighbor to display information about\n" "Display routes learned from neighbor\n") { - union sockunion *su; + union sockunion su; struct peer *peer; - - su = sockunion_str2su (argv[0]); - if (su == NULL) + + if (str2sockunion(argv[0], &su)) { vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE); return CMD_WARNING; } - peer = peer_lookup (NULL, su); + peer = peer_lookup (NULL, &su); if (! peer || ! peer->afc[AFI_IP][SAFI_ENCAP]) { vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE); return CMD_WARNING; } - return bgp_show_encap (vty, AFI_IP, NULL, bgp_show_type_neighbor, su, 0); + return bgp_show_encap (vty, AFI_IP, NULL, bgp_show_type_neighbor, &su, 0); } #ifdef HAVE_IPV6 DEFUN (show_bgp_ipv6_encap_neighbor_routes, @@ -651,24 +650,23 @@ DEFUN (show_bgp_ipv6_encap_neighbor_routes, "Neighbor to display information about\n" "Display routes learned from neighbor\n") { - union sockunion *su; + union sockunion su; struct peer *peer; - su = sockunion_str2su (argv[0]); - if (su == NULL) + if (str2sockunion(argv[0], &su)) { vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE); return CMD_WARNING; } - peer = peer_lookup (NULL, su); + peer = peer_lookup (NULL, &su); if (! peer || ! peer->afc[AFI_IP6][SAFI_ENCAP]) { vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE); return CMD_WARNING; } - return bgp_show_encap (vty, AFI_IP6, NULL, bgp_show_type_neighbor, su, 0); + return bgp_show_encap (vty, AFI_IP6, NULL, bgp_show_type_neighbor, &su, 0); } #endif @@ -687,7 +685,7 @@ DEFUN (show_bgp_ipv4_encap_rd_neighbor_routes, "Display routes learned from neighbor\n") { int ret; - union sockunion *su; + union sockunion su; struct peer *peer; struct prefix_rd prd; @@ -698,21 +696,20 @@ DEFUN (show_bgp_ipv4_encap_rd_neighbor_routes, return CMD_WARNING; } - su = sockunion_str2su (argv[1]); - if (su == NULL) + if (str2sockunion(argv[1], &su)) { vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE); return CMD_WARNING; } - peer = peer_lookup (NULL, su); + peer = peer_lookup (NULL, &su); if (! peer || ! peer->afc[AFI_IP][SAFI_ENCAP]) { vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE); return CMD_WARNING; } - return bgp_show_encap (vty, AFI_IP, &prd, bgp_show_type_neighbor, su, 0); + return bgp_show_encap (vty, AFI_IP, &prd, bgp_show_type_neighbor, &su, 0); } #ifdef HAVE_IPV6 DEFUN (show_bgp_ipv6_encap_rd_neighbor_routes, @@ -730,7 +727,7 @@ DEFUN (show_bgp_ipv6_encap_rd_neighbor_routes, "Display routes learned from neighbor\n") { int ret; - union sockunion *su; + union sockunion su; struct peer *peer; struct prefix_rd prd; @@ -741,21 +738,20 @@ DEFUN (show_bgp_ipv6_encap_rd_neighbor_routes, return CMD_WARNING; } - su = sockunion_str2su (argv[1]); - if (su == NULL) + if (str2sockunion(argv[1], &su)) { vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE); return CMD_WARNING; } - peer = peer_lookup (NULL, su); + peer = peer_lookup (NULL, &su); if (! peer || ! peer->afc[AFI_IP6][SAFI_ENCAP]) { vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE); return CMD_WARNING; } - return bgp_show_encap (vty, AFI_IP6, &prd, bgp_show_type_neighbor, su, 0); + return bgp_show_encap (vty, AFI_IP6, &prd, bgp_show_type_neighbor, &su, 0); } #endif -- 2.39.5