[pcre/f20] Fix memory leaks in pcregrep
Petr Pisar
ppisar at fedoraproject.org
Mon Jul 14 13:35:00 UTC 2014
commit 4515b9984835aeec577fa31ae83c1b28ed090e88
Author: Petr Písař <ppisar at redhat.com>
Date: Mon Jul 14 13:41:28 2014 +0200
Fix memory leaks in pcregrep
...35-Fixed-several-memory-leaks-in-pcregrep.patch | 127 ++++++++++++++++++++
pcre.spec | 5 +
2 files changed, 132 insertions(+), 0 deletions(-)
---
diff --git a/pcre-8.35-Fixed-several-memory-leaks-in-pcregrep.patch b/pcre-8.35-Fixed-several-memory-leaks-in-pcregrep.patch
new file mode 100644
index 0000000..377645d
--- /dev/null
+++ b/pcre-8.35-Fixed-several-memory-leaks-in-pcregrep.patch
@@ -0,0 +1,127 @@
+From bbbc944ef10fe3f383e95b10c13308c0695d0d1a Mon Sep 17 00:00:00 2001
+From: ph10 <ph10 at 2f5784b3-3f2a-0410-8824-cb99058d5e15>
+Date: Tue, 8 Jul 2014 16:16:14 +0000
+Subject: [PATCH] Fixed several memory leaks in pcregrep.
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+git-svn-id: svn://vcs.exim.org/pcre/code/trunk@1492 2f5784b3-3f2a-0410-8824-cb99058d5e15
+Signed-off-by: Petr Písař <ppisar at redhat.com>
+
+Petr Pisar: Ported to 8.35.
+
+diff --git a/pcregrep.c b/pcregrep.c
+index 3e8d05d..fc3f3b2 100644
+--- a/pcregrep.c
++++ b/pcregrep.c
+@@ -455,7 +455,7 @@ Arguments:
+ s pattern string to add
+ after if not NULL points to item to insert after
+
+-Returns: new pattern block
++Returns: new pattern block or NULL on error
+ */
+
+ static patstr *
+@@ -471,6 +471,7 @@ if (strlen(s) > MAXPATLEN)
+ {
+ fprintf(stderr, "pcregrep: pattern is too long (limit is %d bytes)\n",
+ MAXPATLEN);
++ free(p);
+ return NULL;
+ }
+ p->next = NULL;
+@@ -2549,7 +2550,11 @@ while (fgets(buffer, PATBUFSIZE, f) != NULL)
+ afterwards, as a precaution against any later code trying to use it. */
+
+ *patlastptr = add_pattern(buffer, *patlastptr);
+- if (*patlastptr == NULL) return FALSE;
++ if (*patlastptr == NULL)
++ {
++ if (f != stdin) fclose(f);
++ return FALSE;
++ }
+ if (*patptr == NULL) *patptr = *patlastptr;
+
+ /* This loop is needed because compiling a "pattern" when -F is set may add
+@@ -2561,7 +2566,10 @@ while (fgets(buffer, PATBUFSIZE, f) != NULL)
+ {
+ if (!compile_pattern(*patlastptr, pcre_options, popts, TRUE, filename,
+ linenumber))
++ {
++ if (f != stdin) fclose(f);
+ return FALSE;
++ }
+ (*patlastptr)->string = NULL; /* Insurance */
+ if ((*patlastptr)->next == NULL) break;
+ *patlastptr = (*patlastptr)->next;
+@@ -2962,8 +2970,8 @@ if (locale == NULL)
+ locale_from = "LC_CTYPE";
+ }
+
+-/* If a locale has been provided, set it, and generate the tables the PCRE
+-needs. Otherwise, pcretables==NULL, which causes the use of default tables. */
++/* If a locale is set, use it to generate the tables the PCRE needs. Otherwise,
++pcretables==NULL, which causes the use of default tables. */
+
+ if (locale != NULL)
+ {
+@@ -2971,7 +2979,7 @@ if (locale != NULL)
+ {
+ fprintf(stderr, "pcregrep: Failed to set locale %s (obtained from %s)\n",
+ locale, locale_from);
+- return 2;
++ goto EXIT2;
+ }
+ pcretables = pcre_maketables();
+ }
+@@ -2986,7 +2994,7 @@ if (colour_option != NULL && strcmp(colour_option, "never") != 0)
+ {
+ fprintf(stderr, "pcregrep: Unknown colour setting \"%s\"\n",
+ colour_option);
+- return 2;
++ goto EXIT2;
+ }
+ if (do_colour)
+ {
+@@ -3026,7 +3034,7 @@ else if (strcmp(newline, "anycrlf") == 0 || strcmp(newline, "ANYCRLF") == 0)
+ else
+ {
+ fprintf(stderr, "pcregrep: Invalid newline specifier \"%s\"\n", newline);
+- return 2;
++ goto EXIT2;
+ }
+
+ /* Interpret the text values for -d and -D */
+@@ -3039,7 +3047,7 @@ if (dee_option != NULL)
+ else
+ {
+ fprintf(stderr, "pcregrep: Invalid value \"%s\" for -d\n", dee_option);
+- return 2;
++ goto EXIT2;
+ }
+ }
+
+@@ -3050,7 +3058,7 @@ if (DEE_option != NULL)
+ else
+ {
+ fprintf(stderr, "pcregrep: Invalid value \"%s\" for -D\n", DEE_option);
+- return 2;
++ goto EXIT2;
+ }
+ }
+
+@@ -3251,7 +3259,8 @@ EXIT:
+ if (jit_stack != NULL) pcre_jit_stack_free(jit_stack);
+ #endif
+
+-if (main_buffer != NULL) free(main_buffer);
++free(main_buffer);
++free((void *)pcretables);
+
+ free_pattern_chain(patterns);
+ free_pattern_chain(include_patterns);
+--
+1.9.3
+
diff --git a/pcre.spec b/pcre.spec
index bc06187..9cc8b60 100644
--- a/pcre.spec
+++ b/pcre.spec
@@ -25,6 +25,9 @@ Patch4: pcre-8.33-Fix-bad-compile-of-Qx-.-where-x-is-any-character.patch
# Fix empty-matching possessive zero-repeat groups in interpreted mode,
# bug #1119241, upstream bug #1500, in upstream after 8.35
Patch5: pcre-8.33-Fix-empty-matching-possessive-zero-repeat-groups-bug.patch
+# Fix memory leaks in pcregrep, bug #1119257, upstream bug #1502,
+# in upstream after 8.35
+Patch6: pcre-8.35-Fixed-several-memory-leaks-in-pcregrep.patch
BuildRequires: readline-devel
# New libtool to get rid of rpath
BuildRequires: autoconf, automake, libtool
@@ -70,6 +73,7 @@ Utilities demonstrating PCRE capabilities like pcregrep or pcretest.
%patch3 -p1 -b .starting_data
%patch4 -p1 -b .class_with_literal
%patch5 -p1 -b .empty_zero_repeat_group
+%patch6 -p1 -b .pcregrep_leak
# Because of rpath patch
libtoolize --copy --force && autoreconf -vif
# One contributor's name is non-UTF-8
@@ -136,6 +140,7 @@ make check
* Mon Jul 14 2014 Petr Pisar <ppisar at redhat.com> - 8.33-6
- Fix empty-matching possessive zero-repeat groups in interpreted mode
(bug #1119241)
+- Fix memory leaks in pcregrep (bug #1119257)
* Thu Jun 19 2014 Petr Pisar <ppisar at redhat.com> - 8.33-5
- Fix bad starting data when char with more than one other case follows
More information about the scm-commits
mailing list