de-fuzz: Memory leak fix: Need to unwind stack when doing recursive call on non-recursive algorithm

This commit is contained in:
jzmaddock
2017-02-22 12:43:28 +00:00
parent b65bf1b459
commit 85cd85013d

View File

@ -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;
}
}