yandex / pire

Perl Incompatible Regular Expressions library
http://github.com/dprokoptsev/pire/wiki
Other
330 stars 30 forks source link

lexer: fix Parse() memleaks on invalid regexps #38

Closed sorc1 closed 8 years ago

sorc1 commented 8 years ago

Parse() uses bison to parse regexps strings. bison clears its own state stack before exiting from yyparse(). But bison don't support C++ exceptions so its state remains uncleared if an exception is thrown from its yylex() or yyerror() callbacks.

So, we have to delay a Pire::Error exception & re-throw it just after exiting from yyparse().

Delaying exceptions other than Pire::Error is out of scope of the fix.

sorc1 commented 8 years ago

That fixes memleaks on invalid regexps like 'a['.

There are still Parse() memleaks but they're not related to C++ exceptions handling. For example, regexp '(' produces a memleak due to absence of %destructor rules in re_parser.y