mirror of
https://github.com/boostorg/regex.git
synced 2025-07-17 22:32:09 +02:00
de-fuzz: Memory leak fix: Need to unwind stack when doing recursive call on non-recursive algorithm
This commit is contained in:
@ -132,12 +132,19 @@ struct saved_recursion : public saved_state
|
||||
{
|
||||
saved_recursion(int idx, const re_syntax_base* p, Results* pr)
|
||||
: saved_state(14), recursion_id(idx), preturn_address(p), results(*pr)
|
||||
{}
|
||||
{
|
||||
++count;
|
||||
}
|
||||
~saved_recursion() { --count; }
|
||||
int recursion_id;
|
||||
const re_syntax_base* preturn_address;
|
||||
Results results;
|
||||
static int count;
|
||||
};
|
||||
|
||||
template <class Results>
|
||||
int saved_recursion<Results>::count = 0;
|
||||
|
||||
struct saved_change_case : public saved_state
|
||||
{
|
||||
bool icase;
|
||||
@ -464,6 +471,9 @@ bool perl_matcher<BidiIterator, Allocator, traits>::match_startmark()
|
||||
BidiIterator saved_position = position;
|
||||
const re_syntax_base* next_pstate = static_cast<const re_jump*>(pstate->next.p)->alt.p->next.p;
|
||||
pstate = pstate->next.p->next.p;
|
||||
#if !defined(BOOST_NO_EXCEPTIONS)
|
||||
try{
|
||||
#endif
|
||||
bool r = match_all_states();
|
||||
position = saved_position;
|
||||
if(negated)
|
||||
@ -472,6 +482,18 @@ bool perl_matcher<BidiIterator, Allocator, traits>::match_startmark()
|
||||
pstate = next_pstate;
|
||||
else
|
||||
pstate = alt->alt.p;
|
||||
#if !defined(BOOST_NO_EXCEPTIONS)
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
pstate = next_pstate;
|
||||
// unwind all pushed states, apart from anything else this
|
||||
// ensures that all the states are correctly destructed
|
||||
// not just the memory freed.
|
||||
while(unwind(true)){}
|
||||
throw;
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user