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_recursion(int idx, const re_syntax_base* p, Results* pr)
: saved_state(14), recursion_id(idx), preturn_address(p), results(*pr) : saved_state(14), recursion_id(idx), preturn_address(p), results(*pr)
{} {
++count;
}
~saved_recursion() { --count; }
int recursion_id; int recursion_id;
const re_syntax_base* preturn_address; const re_syntax_base* preturn_address;
Results results; Results results;
static int count;
}; };
template <class Results>
int saved_recursion<Results>::count = 0;
struct saved_change_case : public saved_state struct saved_change_case : public saved_state
{ {
bool icase; bool icase;
@ -464,14 +471,29 @@ bool perl_matcher<BidiIterator, Allocator, traits>::match_startmark()
BidiIterator saved_position = position; BidiIterator saved_position = position;
const re_syntax_base* next_pstate = static_cast<const re_jump*>(pstate->next.p)->alt.p->next.p; const re_syntax_base* next_pstate = static_cast<const re_jump*>(pstate->next.p)->alt.p->next.p;
pstate = pstate->next.p->next.p; pstate = pstate->next.p->next.p;
bool r = match_all_states(); #if !defined(BOOST_NO_EXCEPTIONS)
position = saved_position; try{
if(negated) #endif
r = !r; bool r = match_all_states();
if(r) position = saved_position;
if(negated)
r = !r;
if(r)
pstate = next_pstate;
else
pstate = alt->alt.p;
#if !defined(BOOST_NO_EXCEPTIONS)
}
catch(...)
{
pstate = next_pstate; pstate = next_pstate;
else // unwind all pushed states, apart from anything else this
pstate = alt->alt.p; // ensures that all the states are correctly destructed
// not just the memory freed.
while(unwind(true)){}
throw;
}
#endif
break; break;
} }
} }