diff --git a/parser/libapparmor_re/hfa.cc b/parser/libapparmor_re/hfa.cc index a1fea95b0..83aa19783 100644 --- a/parser/libapparmor_re/hfa.cc +++ b/parser/libapparmor_re/hfa.cc @@ -401,7 +401,17 @@ void DFA::update_state_transitions(optflags const &opts, State *state) */ for (Cases::iterator j = cases.begin(); j != cases.end(); j++) { State *target; - target = add_new_state(opts, j->second, nonmatching); + try { + target = add_new_state(opts, j->second, nonmatching); + } catch (int error) { + /* when add_new_state fails, there could still + * be NodeSets in the rest of cases, so clean + * them up before re-throwing the exception */ + for (Cases::iterator k = ++j; k != cases.end(); k++) { + delete k->second; + } + throw error; + } /* Don't insert transition that the otherwise transition * already covers