From: Will Estes <wlestes@users.sourceforge.net> Date: Fri, 20 Oct 2006 19:16:06 +0000 (+0000) Subject: memory leak issues in c++ scanner X-Git-Tag: flex-2-5-34~78 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6ca8e33dbcb2960da332f6d1af0728d0a3e9b1be;p=flex memory leak issues in c++ scanner --- diff --git a/NEWS b/NEWS index 4a72d2a..36fd83e 100644 --- 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 diff --git a/flex.skl b/flex.skl index 482d76c..3cf3064 100644 --- 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 diff --git a/tests/test-c++-multiple-scanners/main.cpp b/tests/test-c++-multiple-scanners/main.cpp index aa89949..08fe2c1 100644 --- a/tests/test-c++-multiple-scanners/main.cpp +++ b/tests/test-c++-multiple-scanners/main.cpp @@ -47,6 +47,8 @@ main ( int argc, char** argv ) S2_ok = S2->yylex(); } printf("TEST RETURNING OK.\n"); + delete S1; + delete S2; return 0; } diff --git a/tests/test-c-cpp-nr/scanner.l b/tests/test-c-cpp-nr/scanner.l index 63543e4..e184008 100644 --- a/tests/test-c-cpp-nr/scanner.l +++ b/tests/test-c-cpp-nr/scanner.l @@ -51,6 +51,7 @@ main () yyin = stdin; yyout = stdout; yylex(); + yylex_destroy(); printf("TEST RETURNING OK.\n"); return 0; }