summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Franke <nobody@nowhere.ws>2016-06-14 20:06:59 +0200
committerDonald Sharp <sharpd@cumulusnetworks.com>2016-10-20 20:28:26 -0400
commitb84ee83b10473391caa7a8dbc3d7a21f9558a95d (patch)
tree201cde78b448c0765a19f2015d19274a6fb12579
parent6e71194f115ece3985665b7c6e22818b79c3c533 (diff)
bgpd: don't leak memory in community_regexp_include
Signed-off-by: Christian Franke <chris@opensourcerouting.org> Signed-off-by: Christian Franke <chris@opensourcerouting.org> Acked-by: Donald Sharp <sharpd@cumulusnetworks.com>
-rw-r--r--bgpd/bgp_clist.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/bgpd/bgp_clist.c b/bgpd/bgp_clist.c
index 12c936b190..9032b1e2f4 100644
--- a/bgpd/bgp_clist.c
+++ b/bgpd/bgp_clist.c
@@ -403,17 +403,22 @@ community_str_get (struct community *com, int i)
static int
community_regexp_include (regex_t * reg, struct community *com, int i)
{
- const char *str;
+ char *str;
+ int rv;
/* When there is no communities attribute it is treated as empty
* string. */
if (com == NULL || com->size == 0)
- str = "";
+ str = XSTRDUP(MTYPE_COMMUNITY_STR, "");
else
str = community_str_get (com, i);
/* Regular expression match. */
- if (regexec (reg, str, 0, NULL, 0) == 0)
+ rv = regexec (reg, str, 0, NULL, 0);
+
+ XFREE(MTYPE_COMMUNITY_STR, str);
+
+ if (rv == 0)
return 1;
/* No match. */