]> git.saurik.com Git - bison.git/commitdiff
Fix memory leaks in scanners generated by at least Flex 2.5.9 and
authorJoel E. Denny <jdenny@ces.clemson.edu>
Fri, 10 Nov 2006 05:26:26 +0000 (05:26 +0000)
committerJoel E. Denny <jdenny@ces.clemson.edu>
Fri, 10 Nov 2006 05:26:26 +0000 (05:26 +0000)
later.  Reported by Paul Eggert in
<http://lists.gnu.org/archive/html/bison-patches/2006-11/msg00014.html>.
* src/flex-scanner.h (yylex_destroy): Define for Flex before 2.5.9.
* src/scan-code.l (translate_action): Don't bother invoking
yy_delete_buffer (YY_CURRENT_BUFFER) before creating the first buffer.
(code_scanner_free): Instead of invoking
yy_delete_buffer (YY_CURRENT_BUFFER) directly, invoke yylex_destroy,
which frees more.
* src/scan-gram.l (gram_scanner_free): Likewise.
* src/scan-skel.l (scan_skel): Likewise.

ChangeLog
src/flex-scanner.h
src/scan-code.l
src/scan-gram.l
src/scan-skel.l

index d558bacaf471e351455fbd0c4b39a29da5120aac..2d954577c5a8d1e8b48b43393cbc88d6407228e3 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2006-11-10  Joel E. Denny  <jdenny@ces.clemson.edu>
+
+       Fix memory leaks in scanners generated by at least Flex 2.5.9 and
+       later.  Reported by Paul Eggert in
+       <http://lists.gnu.org/archive/html/bison-patches/2006-11/msg00014.html>.
+       * src/flex-scanner.h (yylex_destroy): Define for Flex before 2.5.9.
+       * src/scan-code.l (translate_action): Don't bother invoking
+       yy_delete_buffer (YY_CURRENT_BUFFER) before creating the first buffer.
+       (code_scanner_free): Instead of invoking
+       yy_delete_buffer (YY_CURRENT_BUFFER) directly, invoke yylex_destroy,
+       which frees more.
+       * src/scan-gram.l (gram_scanner_free): Likewise.
+       * src/scan-skel.l (scan_skel): Likewise.
+
 2006-11-09  Joel E. Denny  <jdenny@ces.clemson.edu>
 
        * src/files.c (tr): Change return type to void.
index 3e16234c553605ad52e47c05e6e7985ff75589f3..5d08dec6a7bffa0b0d81b5089317dd239ae5b282 100644 (file)
@@ -50,6 +50,19 @@ int   FLEX_PREFIX (lex_destroy) (void);
 # define yytext  FLEX_PREFIX (text)
 #endif
 
+/* Non-reentrant scanners generated by Flex 2.5.9 and later (and some earlier
+   versions according to the Flex manual) leak memory if yylex_destroy is not
+   invoked.  However, yylex_destroy is not defined before Flex 2.5.9, so give
+   an implementation here that at least appears to work with Flex 2.5.4.  */
+#if !defined(YY_FLEX_MAJOR_VERSION) || YY_FLEX_MAJOR_VERSION < 2 \
+    || (YY_FLEX_MAJOR_VERSION == 2 \
+        && (!defined(YY_FLEX_MINOR_VERSION) || YY_FLEX_MINOR_VERSION < 5 \
+            || (YY_FLEX_MINOR_VERSION == 5 \
+                && (!defined(YY_FLEX_SUBMINOR_VERSION) \
+                    || YY_FLEX_SUBMINOR_VERSION < 9))))
+# define yylex_destroy() yy_delete_buffer (YY_CURRENT_BUFFER)
+#endif
+
 /* OBSTACK_FOR_STRING -- Used to store all the characters that we need to
    keep (to construct ID, STRINGS etc.).  Use the following macros to
    use it.
index 6b33e015ecfc367687156b0ea34c9a99da473d5f..0a338b4e6fac23569cdfc5e9d2b336c9fb2881f8 100644 (file)
@@ -380,8 +380,6 @@ translate_action (int sc_context, symbol_list *rule, char const *a, location l)
   if (!initialized)
     {
       obstack_init (&obstack_for_string);
-      /* The initial buffer, never used. */
-      yy_delete_buffer (YY_CURRENT_BUFFER);
       yy_flex_debug = 0;
       initialized = true;
     }
@@ -422,5 +420,5 @@ code_scanner_free (void)
 {
   obstack_free (&obstack_for_string, 0);
   /* Reclaim Flex's buffers.  */
-  yy_delete_buffer (YY_CURRENT_BUFFER);
+  yylex_destroy ();
 }
index 6fa9f220f3ec5cc9f09f967ca768caf0a4379b30..88369ea6b50097b1d2d0f17f5d1cf6e250983646 100644 (file)
@@ -800,5 +800,5 @@ gram_scanner_free (void)
 {
   obstack_free (&obstack_for_string, 0);
   /* Reclaim Flex's buffers.  */
-  yy_delete_buffer (YY_CURRENT_BUFFER);
+  yylex_destroy ();
 }
index e787d288a04dcdf236e784e2c46cea4815eb95e8..6c516097e64cf307041b66e0d1f2e80e90e552d6 100644 (file)
@@ -121,5 +121,5 @@ scan_skel (FILE *in)
   skel__flex_debug = trace_flag & trace_skeleton;
   skel_lex ();
   /* Reclaim Flex's buffers.  */
-  yy_delete_buffer (YY_CURRENT_BUFFER);
+  yylex_destroy ();
 }