Package: flex
Version: 2.5.31-37
Tags: patch
Followup-For: Bug #233215

Attaching a patch that makes the yyFlexLexer destructor use the same code as
yylex_destroy. I have confirmed that this removes a memory leak that I was
having in my c++ scanner, using "valgrind --leak-check=full -v ./scanner
input".

// Erik


-- System Information:
Debian Release: testing/unstable
  APT prefers unstable
  APT policy: (500, 'unstable')
Architecture: i386 (i686)
Shell:  /bin/sh linked to /bin/bash
Kernel: Linux 2.6.15-zem1
Locale: LANG=en_US, LC_CTYPE=sv_SE (charmap=ISO-8859-1)

Versions of packages flex depends on:
ii  debconf [debconf-2.0]         1.4.70     Debian configuration management sy
ii  libc6                         2.3.6-1    GNU C Library: Shared libraries an
ii  m4                            1.4.4-1    a macro processing language

Versions of packages flex recommends:
ii  gcc [c-compiler]              4:4.0.2-2  The GNU C compiler
ii  gcc-3.3 [c-compiler]          1:3.3.6-12 The GNU C compiler
ii  gcc-4.0 [c-compiler]          4.0.2-9    The GNU C compiler

-- debconf information:
  flex/upgrade/pre_2.5.5: false
--- flex.skl-ORG        2006-02-23 01:00:25.000000000 +0100
+++ flex.skl    2006-02-23 02:23:50.000000000 +0100
@@ -1451,13 +1451,6 @@
 ]])
 }
 
-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 )
@@ -2761,9 +2754,14 @@
 
 %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();
 
@@ -2778,6 +2776,12 @@
        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
 %# This is the m4 way to say "if (stack_used || is_reentrant){ destroy_stack }"
 m4_ifdef( [[M4_YY_STACK_USED]], [[m4_define([[M4_YY_DESTROY_START_STACK]])]])
 m4_ifdef( [[M4_YY_REENTRANT]],  [[m4_define([[M4_YY_DESTROY_START_STACK]])]])
@@ -2798,6 +2802,7 @@
     yyfree ( yyscanner M4_YY_CALL_LAST_ARG );
 %endif
     return 0;
+%endif
 }
 %endif
 

Reply via email to