]> git.puffer.fish Git - mirror/frr.git/commitdiff
bgpd: don't leak memory in community_regexp_include
authorChristian Franke <nobody@nowhere.ws>
Tue, 14 Jun 2016 18:06:59 +0000 (20:06 +0200)
committerDonald Sharp <sharpd@cumulusnetworks.com>
Fri, 21 Oct 2016 00:28:26 +0000 (20:28 -0400)
Signed-off-by: Christian Franke <chris@opensourcerouting.org>
Signed-off-by: Christian Franke <chris@opensourcerouting.org>
Acked-by: Donald Sharp <sharpd@cumulusnetworks.com>
bgpd/bgp_clist.c

index 12c936b190a5499730e8e37e5c9b5e5d7cb1b324..9032b1e2f4fbaef48791deaa241184d0e54d5733 100644 (file)
@@ -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.  */