]> Savannah Git Hosting - gnulib.git/commitdiff
regex: fix memory leak in compiler
authorPaul Eggert <eggert@penguin.cs.ucla.edu>
Thu, 19 Jun 2014 15:51:30 +0000 (08:51 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Thu, 19 Jun 2014 15:58:59 +0000 (08:58 -0700)
Fix by Andreas Schwab in:
https://sourceware.org/ml/libc-alpha/2014-06/msg00462.html
* lib/regcomp.c (parse_expression): Deallocate partially
constructed tree before returning error.

ChangeLog
lib/regcomp.c

index 687a79d7b2dd6fcb4a371e81736128df3b6567d4..53b28711b7cff505383badda1039730cff71668d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2014-06-19  Paul Eggert  <eggert@penguin.cs.ucla.edu>
 
+       regex: fix memory leak in compiler
+       Fix by Andreas Schwab in:
+       https://sourceware.org/ml/libc-alpha/2014-06/msg00462.html
+       * lib/regcomp.c (parse_expression): Deallocate partially
+       constructed tree before returning error.
+
        regex: merge patch from libc
        2014-02-12  Joseph Myers  <joseph@codesourcery.com>
        Combine __USE_BSD and __USE_SVID into __USE_MISC.
index 56faf11c4236ac27d72ab2a689172412164f449c..16d0e2159519a130c17d6bf1da6faceae4c43d06 100644 (file)
@@ -2460,14 +2460,22 @@ parse_expression (re_string_t *regexp, regex_t *preg, re_token_t *token,
   while (token->type == OP_DUP_ASTERISK || token->type == OP_DUP_PLUS
         || token->type == OP_DUP_QUESTION || token->type == OP_OPEN_DUP_NUM)
     {
-      tree = parse_dup_op (tree, regexp, dfa, token, syntax, err);
-      if (BE (*err != REG_NOERROR && tree == NULL, 0))
-       return NULL;
+      bin_tree_t *dup_tree = parse_dup_op (tree, regexp, dfa, token,
+                                          syntax, err);
+      if (BE (*err != REG_NOERROR && dup_tree == NULL, 0))
+       {
+         if (tree != NULL)
+           postorder (tree, free_tree, NULL);
+         return NULL;
+       }
+      tree = dup_tree;
       /* In BRE consecutive duplications are not allowed.  */
       if ((syntax & RE_CONTEXT_INVALID_DUP)
          && (token->type == OP_DUP_ASTERISK
              || token->type == OP_OPEN_DUP_NUM))
        {
+         if (tree != NULL)
+           postorder (tree, free_tree, NULL);
          *err = REG_BADRPT;
          return NULL;
        }