aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2014-06-22 22:06:12 +0300
committerArnold D. Robbins <arnold@skeeve.com>2014-06-22 22:06:12 +0300
commit7cdd5a510d45228574c34b066b2ddac833fef118 (patch)
tree8185af2a687f969ef280f139103028141b75f1dd
parent46b2d10640dc4404680fc7ffc670dd06feb5ecf3 (diff)
downloadegawk-7cdd5a510d45228574c34b066b2ddac833fef118.tar.gz
egawk-7cdd5a510d45228574c34b066b2ddac833fef118.tar.bz2
egawk-7cdd5a510d45228574c34b066b2ddac833fef118.zip
Fix memory leak in regcomp.c.
-rw-r--r--ChangeLog10
-rw-r--r--regcomp.c14
2 files changed, 21 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index 3d7dd673..b385cffb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2014-06-22 Paul Eggert <eggert@penguin.cs.ucla.edu>
+
+ Bring in from GNULIB:
+
+ 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.
+
2014-06-19 Arnold D. Robbins <arnold@skeeve.com>
* builtin.c (do_sub): Add more info to leading comment.
diff --git a/regcomp.c b/regcomp.c
index 776b7134..a62364c9 100644
--- a/regcomp.c
+++ b/regcomp.c
@@ -2476,14 +2476,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;
}