Memory leak in flex-2.5.4a

Don Richardson DRichardson@wavo.com
Thu Jul 12 12:46:00 GMT 2001


Title: Memory leak in flex-2.5.4a





I have found and fixed a huge memory leak in flex-2.5.4a.
It is big enough, and obvious enough that I suspect someone else
has already found and fixed it. However, I could find no reference
to it when I searched this site, nor on the web in general.


The bug is in skel.c, generated from flex.skl. I have attached
both files.
The changed code starts on line 1091 in flex.skl, and on line 1096 in skel.c.


Here is an excerpt showing the lines I have added (underlined)


**********************************************************************************************************


void yyFlexLexer::yy_switch_to_buffer( YY_BUFFER_STATE new_buffer )
%*
        {
        if ( yy_current_buffer == new_buffer )
                return;


        if ( yy_current_buffer )
                {
                /* Flush out information for old buffer. */
                *yy_c_buf_p = yy_hold_char;
                yy_current_buffer->yy_buf_pos = yy_c_buf_p;
                yy_current_buffer->yy_n_chars = yy_n_chars;
                }


        /* Here we fix a huge memory leak - Before this fix 
         * yy_current_buffer was never freed. 7-11-2001 
         */
        YY_BUFFER_STATE  Temp = yy_current_buffer;
        yy_current_buffer = new_buffer;
        if (NULL != Temp)
        {
                yy_delete_buffer (Temp);
        }


        yy_load_buffer_state();


        /* We don't actually know whether we did this switch during
         * EOF (yywrap()) processing, but the only time this flag
         * is looked at is after yywrap() is called, so it's safe
         * to go ahead and always set it.
         */
        yy_did_buffer_switch_on_eof = 1;
        }
*****************************************************************************************************


Don Richardson, Acquire Media Corporation
drichardson@acquiremedia.com


 <<flex.skl>> 
 <<scan.c>> 



flex.skl
scan.c

-------------- next part --------------
A non-text attachment was scrubbed...
Name: flex.skl
Type: text/x-c
Size: 34160 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/binutils/attachments/20010712/b3b60bc2/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: scan.c
Type: text/x-c
Size: 110869 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/binutils/attachments/20010712/b3b60bc2/attachment-0001.bin>


More information about the Binutils mailing list