grep-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

grep branch, master, updated. v3.7-95-ge2aec8c


From: Paul Eggert
Subject: grep branch, master, updated. v3.7-95-ge2aec8c
Date: Fri, 24 Jun 2022 19:37:02 -0400 (EDT)

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "grep".

The branch, master has been updated
       via  e2aec8c91e9d6ed3fc76f9f145dec8a456ce623a (commit)
      from  225d921887128df688722f40c69d41e4ed847b26 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://git.savannah.gnu.org/cgit/grep.git/commit/?id=e2aec8c91e9d6ed3fc76f9f145dec8a456ce623a


commit e2aec8c91e9d6ed3fc76f9f145dec8a456ce623a
Author: Paul Eggert <eggert@cs.ucla.edu>
Date:   Fri Jun 24 17:53:34 2022 -0500

    grep: fix regex compilation memory leaks
    
    Problem reported by Jim Meyering in:
    https://lists.gnu.org/r/grep-devel/2022-06/msg00012.html
    * src/dfasearch.c (regex_compile): Fix memory leaks when SYNTAX_ONLY.

diff --git a/src/dfasearch.c b/src/dfasearch.c
index 8d832f0..2720b3a 100644
--- a/src/dfasearch.c
+++ b/src/dfasearch.c
@@ -144,26 +144,34 @@ regex_compile (struct dfa_comp *dc, char const *p, idx_t 
len,
                idx_t pcount, idx_t lineno, reg_syntax_t syntax_bits,
                bool syntax_only)
 {
-  struct re_pattern_buffer pat0;
-  struct re_pattern_buffer *pat = syntax_only ? &pat0 : &dc->patterns[pcount];
-  pat->buffer = NULL;
-  pat->allocated = 0;
+  struct re_pattern_buffer pat;
+  pat.buffer = NULL;
+  pat.allocated = 0;
 
   /* Do not use a fastmap with -i, to work around glibc Bug#20381.  */
   verify (UCHAR_MAX < IDX_MAX);
   idx_t uchar_max = UCHAR_MAX;
-  pat->fastmap = (syntax_only | match_icase) ? NULL : ximalloc (uchar_max + 1);
+  pat.fastmap = syntax_only | match_icase ? NULL : ximalloc (uchar_max + 1);
 
-  pat->translate = NULL;
+  pat.translate = NULL;
 
   if (syntax_only)
     re_set_syntax (syntax_bits | RE_NO_SUB);
   else
     re_set_syntax (syntax_bits);
 
-  char const *err = re_compile_pattern (p, len, pat);
+  char const *err = re_compile_pattern (p, len, &pat);
   if (!err)
-    return true;
+    {
+      if (syntax_only)
+        regfree (&pat);
+      else
+        dc->patterns[pcount] = pat;
+
+      return true;
+    }
+
+  free (pat.fastmap);
 
   /* Emit a filename:lineno: prefix for patterns taken from files.  */
   idx_t pat_lineno;

-----------------------------------------------------------------------

Summary of changes:
 src/dfasearch.c | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)


hooks/post-receive
-- 
grep



reply via email to

[Prev in Thread] Current Thread [Next in Thread]