From aa6ec754f3b4b1df81d186480c534b6486a1e6ee Mon Sep 17 00:00:00 2001 From: Andreas Schwab Date: Fri, 20 Jun 2014 12:41:27 +0200 Subject: Fix another memory leak in regexp compiler (BZ #17069) --- posix/bug-regex36.c | 4 ++-- posix/regcomp.c | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) (limited to 'posix') diff --git a/posix/bug-regex36.c b/posix/bug-regex36.c index 3dda026585..59e2b6d321 100644 --- a/posix/bug-regex36.c +++ b/posix/bug-regex36.c @@ -1,4 +1,4 @@ -/* Test regcomp not leaking memory on invalid repetition operator +/* Test regcomp not leaking memory on parse errors Copyright (C) 2014 Free Software Foundation, Inc. This file is part of the GNU C Library. @@ -24,6 +24,6 @@ main (int argc, char **argv) { regex_t r; mtrace (); - regcomp (&r, "[a]\\{-2,}", 0); + regcomp (&r, "[a]\\|[a]\\{-2,}", 0); regfree (&r); } diff --git a/posix/regcomp.c b/posix/regcomp.c index a5020be192..076eca3e7c 100644 --- a/posix/regcomp.c +++ b/posix/regcomp.c @@ -2154,7 +2154,11 @@ parse_reg_exp (re_string_t *regexp, regex_t *preg, re_token_t *token, { branch = parse_branch (regexp, preg, token, syntax, nest, err); if (BE (*err != REG_NOERROR && branch == NULL, 0)) - return NULL; + { + if (tree != NULL) + postorder (tree, free_tree, NULL); + return NULL; + } } else branch = NULL; -- cgit v1.2.3