Revision: 1492
http://vcs.pcre.org/viewvc?view=rev&revision=1492
Author: ph10
Date: 2014-07-08 17:16:14 +0100 (Tue, 08 Jul 2014)
Log Message:
-----------
Fixed several memory leaks in pcregrep.
Modified Paths:
--------------
code/trunk/ChangeLog
code/trunk/pcregrep.c
Modified: code/trunk/ChangeLog
===================================================================
--- code/trunk/ChangeLog 2014-07-07 07:11:16 UTC (rev 1491)
+++ code/trunk/ChangeLog 2014-07-08 16:16:14 UTC (rev 1492)
@@ -79,7 +79,9 @@
16. The Unicode data tables have been updated to Unicode 7.0.0.
+17. Fixed a number of memory leaks in pcregrep.
+
Version 8.35 04-April-2014
--------------------------
Modified: code/trunk/pcregrep.c
===================================================================
--- code/trunk/pcregrep.c 2014-07-07 07:11:16 UTC (rev 1491)
+++ code/trunk/pcregrep.c 2014-07-08 16:16:14 UTC (rev 1492)
@@ -455,7 +455,7 @@
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 @@
{
fprintf(stderr, "pcregrep: pattern is too long (limit is %d bytes)\n",
MAXPATLEN);
+ free(p);
return NULL;
}
p->next = NULL;
@@ -2549,7 +2550,11 @@
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 @@
{
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 @@
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 @@
{
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 @@
{
fprintf(stderr, "pcregrep: Unknown colour setting \"%s\"\n",
colour_option);
- return 2;
+ goto EXIT2;
}
if (do_colour)
{
@@ -3026,7 +3034,7 @@
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 @@
else
{
fprintf(stderr, "pcregrep: Invalid value \"%s\" for -d\n", dee_option);
- return 2;
+ goto EXIT2;
}
}
@@ -3050,7 +3058,7 @@
else
{
fprintf(stderr, "pcregrep: Invalid value \"%s\" for -D\n", DEE_option);
- return 2;
+ goto EXIT2;
}
}
@@ -3251,7 +3259,8 @@
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);