bgpd: Fix memory leak of some "show ip bgp neighbor" commands
sockunion_str2su() use is prone to memory leaks. Remove it's use all over
the code.
At least these commands leaked a sockunion union:
- show ip bgp vpnv4 ... routes
- show ip bgp ... received prefix-filter
Signed-off-by: Jorge Boncompte [DTI2] <jorge@dti2.net>
Signed-off-by: David Lamparter <equinox@diac24.net>
diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c
index 9f8d823..d96224d 100644
--- a/bgpd/bgp_route.c
+++ b/bgpd/bgp_route.c
@@ -10202,15 +10202,18 @@
"Display the prefixlist filter\n")
{
char name[BUFSIZ];
- union sockunion *su;
+ union sockunion su;
struct peer *peer;
- int count;
+ int count, ret;
- su = sockunion_str2su (argv[0]);
- if (su == NULL)
- return CMD_WARNING;
+ ret = str2sockunion (argv[0], &su);
+ if (ret < 0)
+ {
+ 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)
return CMD_WARNING;
@@ -10241,15 +10244,18 @@
"Display the prefixlist filter\n")
{
char name[BUFSIZ];
- union sockunion *su;
+ union sockunion su;
struct peer *peer;
- int count;
+ int count, ret;
- su = sockunion_str2su (argv[1]);
- if (su == NULL)
- return CMD_WARNING;
+ ret = str2sockunion (argv[1], &su);
+ if (ret < 0)
+ {
+ 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)
return CMD_WARNING;
@@ -10312,15 +10318,18 @@
"Display the prefixlist filter\n")
{
char name[BUFSIZ];
- union sockunion *su;
+ union sockunion su;
struct peer *peer;
- int count;
+ int count, ret;
- su = sockunion_str2su (argv[0]);
- if (su == NULL)
- return CMD_WARNING;
+ ret = str2sockunion (argv[0], &su);
+ if (ret < 0)
+ {
+ 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)
return CMD_WARNING;
@@ -10394,10 +10403,10 @@
"Display the prefixlist filter\n")
{
char name[BUFSIZ];
- union sockunion *su;
+ union sockunion su;
struct peer *peer;
struct bgp *bgp;
- int count;
+ int count, ret;
/* BGP structure lookup. */
bgp = bgp_lookup_by_name (argv[0]);
@@ -10407,11 +10416,14 @@
return CMD_WARNING;
}
- su = sockunion_str2su (argv[1]);
- if (su == NULL)
- return CMD_WARNING;
+ ret = str2sockunion (argv[1], &su);
+ if (ret < 0)
+ {
+ vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
+ return CMD_WARNING;
+ }
- peer = peer_lookup (bgp, su);
+ peer = peer_lookup (bgp, &su);
if (! peer)
return CMD_WARNING;