]> granicus.if.org Git - flex/commitdiff
memory leak issues in c++ scanner
authorWill Estes <wlestes@users.sourceforge.net>
Fri, 20 Oct 2006 19:16:06 +0000 (19:16 +0000)
committerWill Estes <wlestes@users.sourceforge.net>
Fri, 20 Oct 2006 19:16:06 +0000 (19:16 +0000)
NEWS
flex.skl
tests/test-c++-multiple-scanners/main.cpp
tests/test-c-cpp-nr/scanner.l

diff --git a/NEWS b/NEWS
index 4a72d2a3b769b6ac35c0b0cd1bf8b7a63a97500f..36fd83e876ea26e3ad1253e79b4674a59621a541 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -5,7 +5,10 @@ See the file COPYING for copying conditions.
 
 * after version 2.5.33
 
-* added new unit test for c++ and yywrap
+** memory leaks removed from the C++ scanner (but the C++ scanner is
+still experimental and may change radically without notice)
+
+** added new unit test for c++ and yywrap
 
 ** portability fixes to some unit tests
 
index 482d76c671bc8adc539869c4096c9d5a052e07ee..3cf3064bee45aa699f5db38b36638a633d6edce9 100644 (file)
--- a/flex.skl
+++ b/flex.skl
@@ -1462,13 +1462,6 @@ m4_ifdef( [[M4_YY_USES_REJECT]],
 ]])
 }
 
-yyFlexLexer::~yyFlexLexer()
-{
-       delete [] yy_state_buf;
-       yyfree( yy_start_stack M4_YY_CALL_LAST_ARG );
-       yy_delete_buffer( YY_CURRENT_BUFFER M4_YY_CALL_LAST_ARG);
-}
-
 void yyFlexLexer::switch_streams( std::istream* new_in, std::ostream* new_out )
 {
        if ( new_in )
@@ -2781,9 +2774,14 @@ m4_ifdef( [[M4_YY_TEXT_IS_ARRAY]],
 %endif
 
 
-%if-c-only SNIP! this currently causes conflicts with the c++ scanner
+%if-c-or-c++
+%if-c-only
 /* yylex_destroy is for both reentrant and non-reentrant scanners. */
 int yylex_destroy  YYFARGS0(void)
+%endif
+%if-c++-only
+yyFlexLexer::~yyFlexLexer()
+%endif
 {
     M4_YY_DECL_GUTS_VAR();
 
@@ -2798,6 +2796,12 @@ int yylex_destroy  YYFARGS0(void)
        yyfree(YY_G(yy_buffer_stack) M4_YY_CALL_LAST_ARG);
        YY_G(yy_buffer_stack) = NULL;
 
+%if-c++-only
+       delete [] YY_G(yy_state_buf);
+       yyfree(YY_G(yy_start_stack) M4_YY_CALL_LAST_ARG );
+%endif
+
+%if-c-only
 m4_ifdef( [[M4_YY_HAS_START_STACK_VARS]],
 [[
     /* Destroy the start condition stack. */
@@ -2821,6 +2825,7 @@ m4_ifdef( [[M4_YY_USES_REJECT]],
     yyscanner = NULL;
 %endif
     return 0;
+%endif
 }
 %endif
 
index aa89949818b126fb22ea85408d4d2f9abafea1c4..08fe2c15fbf7b0cf9f3999b32accbfbe75e45847 100644 (file)
@@ -47,6 +47,8 @@ main ( int argc, char** argv )
             S2_ok = S2->yylex();
     }
     printf("TEST RETURNING OK.\n");
+    delete S1;
+    delete S2;
     return 0;
 }
 
index 63543e4ccced34eb7fd08e69dfa49bda10ba3885..e1840083d0330c7ccc4b70e7d2cca1d8e1b29249 100644 (file)
@@ -51,6 +51,7 @@ main ()
     yyin = stdin;
     yyout = stdout;
     yylex();
+    yylex_destroy();
     printf("TEST RETURNING OK.\n");
     return 0;
 }