summaryrefslogtreecommitdiff
path: root/posix/regcomp.c
diff options
context:
space:
mode:
authorAndreas Schwab <schwab@linux-m68k.org>2014-06-19 15:38:03 +0200
committerAndreas Schwab <schwab@linux-m68k.org>2014-06-19 19:00:03 +0200
commit4d43ef1e7434d7d419afbcd754931cb0c794763c (patch)
tree90c7ac031522e1cf820330f4ad79a267322b5060 /posix/regcomp.c
parent51a7380b8968251a49a4c5b0bc7ed1af5b0512c6 (diff)
downloadglibc-4d43ef1e7434d7d419afbcd754931cb0c794763c.tar.gz
Fix memory leak in regexp compiler (BZ #17069)
Diffstat (limited to 'posix/regcomp.c')
-rw-r--r--posix/regcomp.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/posix/regcomp.c b/posix/regcomp.c
index 921d0f49a3..a5020be192 100644
--- a/posix/regcomp.c
+++ b/posix/regcomp.c
@@ -2415,14 +2415,21 @@ 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;
}