[Pcre-svn] [298] code/trunk: Fix memory leak in pcre2grep.

Top Page
Delete this message
Author: Subversion repository
Date:  
To: pcre-svn
Subject: [Pcre-svn] [298] code/trunk: Fix memory leak in pcre2grep.
Revision: 298
          http://www.exim.org/viewvc/pcre2?view=rev&revision=298
Author:   ph10
Date:     2015-06-30 11:28:59 +0100 (Tue, 30 Jun 2015)
Log Message:
-----------
Fix memory leak in pcre2grep.


Modified Paths:
--------------
    code/trunk/ChangeLog
    code/trunk/src/pcre2grep.c


Modified: code/trunk/ChangeLog
===================================================================
--- code/trunk/ChangeLog    2015-06-28 13:31:24 UTC (rev 297)
+++ code/trunk/ChangeLog    2015-06-30 10:28:59 UTC (rev 298)
@@ -1,7 +1,7 @@
 Change Log for PCRE2
 --------------------


-Version 10.20 16-June-2015
+Version 10.20 30-June-2015
--------------------------

1. Callouts with string arguments have been added.
@@ -180,7 +180,9 @@
47. JIT should return with error when the compiled pattern requires
more stack space than the maximum.

+48. Fixed a memory leak in pcre2grep when a locale is set.

+
Version 10.10 06-March-2015
---------------------------


Modified: code/trunk/src/pcre2grep.c
===================================================================
--- code/trunk/src/pcre2grep.c    2015-06-28 13:31:24 UTC (rev 297)
+++ code/trunk/src/pcre2grep.c    2015-06-30 10:28:59 UTC (rev 298)
@@ -171,6 +171,8 @@
 static BOOL use_jit = FALSE;
 #endif


+static const uint8_t *character_tables = NULL;
+
static uint32_t pcre2_options = 0;
static uint32_t process_options = 0;
static uint32_t match_limit = 0;
@@ -2984,7 +2986,8 @@
locale_from = "LC_CTYPE";
}

-/* If a locale is set, use it to generate the tables the PCRE needs. */
+/* If a locale is set, use it to generate the tables the PCRE needs. Passing
+NULL to pcre2_maketables() means that malloc() is used to get the memory. */

 if (locale != NULL)
   {
@@ -2994,7 +2997,8 @@
       locale, locale_from);
     goto EXIT2;
     }
-  pcre2_set_character_tables(compile_context, pcre2_maketables(NULL));
+  character_tables = pcre2_maketables(NULL);
+  pcre2_set_character_tables(compile_context, character_tables);
   }


/* Sort out colouring */
@@ -3232,6 +3236,8 @@
#endif

free(main_buffer);
+free((void *)character_tables);
+
pcre2_compile_context_free(compile_context);
pcre2_match_context_free(match_context);
pcre2_match_data_free(match_data);