flex icon indicating copy to clipboard operation
flex copied to clipboard

`yyrestart(0)` allocates a buffer (may lead to a space leak)

Open andreasabel opened this issue 4 years ago • 0 comments

yyrestart does not check whether its argument is a null pointer, it unconditionally allocates a buffer. This is then leaked if we use yy_scan_string (followed by yy_delete_buffer).
This isn't fixed by yylex_destroy (as e.g. suggested in https://www.javaer101.com/en/article/37968820.html).

One can argue that one should never call yyrestart(0). (Is that actually true?)

But one can also argue for more robust APIs. So yyrestart(0) should be a no-op, maybe. (I am not familiar enough with the internals to say this for sure.)

Context: https://github.com/BNFC/bnfc/issues/347

andreasabel avatar Mar 19 '21 07:03 andreasabel