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