diff --git a/ChangeLog b/ChangeLog index 3fc8177de..511ea8c89 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2010-01-20 Damien Lefortier + + When iterating a hash_map, be careful not to delete i->first + before doing ++i to avoid memory issues. + + * src/tgba/taatgba.cc, src/tgba/taatgba.hh, + src/tgba/tgbaexplicit.cc, src/tgba/tgbaexplicit.hh: Fix them. + 2010-01-20 Damien Lefortier Minor fixes to compile with GCC 3.3 diff --git a/src/tgba/taatgba.cc b/src/tgba/taatgba.cc index 8e5afbdde..1b12d4993 100644 --- a/src/tgba/taatgba.cc +++ b/src/tgba/taatgba.cc @@ -302,8 +302,13 @@ namespace spot delete succ_[i]->dst; delete succ_[i]; } - for (seen_map::iterator i = seen_.begin(); i != seen_.end(); ++i) - delete i->first; + for (seen_map::iterator i = seen_.begin(); i != seen_.end();) + { + // Advance the iterator before deleting the formula. + const spot::state_set* s = i->first; + ++i; + delete s; + } } void @@ -350,6 +355,18 @@ namespace spot | taa_tgba_string | `----------------*/ + taa_tgba_string::~taa_tgba_string() + { + ns_map::iterator i; + for (i = name_state_map_.begin(); i != name_state_map_.end(); ++i) + { + taa_tgba::state::iterator i2; + for (i2 = i->second->begin(); i2 != i->second->end(); ++i2) + delete *i2; + delete i->second; + } + } + std::string taa_tgba_string::label_to_string(const label_t& label) const { @@ -370,7 +387,16 @@ namespace spot { ns_map::iterator i; for (i = name_state_map_.begin(); i != name_state_map_.end(); ++i) - i->first->destroy(); + { + taa_tgba::state::iterator i2; + for (i2 = i->second->begin(); i2 != i->second->end(); ++i2) + delete *i2; + // Advance the iterator before deleting the formula. + const ltl::formula* s = i->first; + delete i->second; + ++i; + s->destroy(); + } } std::string diff --git a/src/tgba/taatgba.hh b/src/tgba/taatgba.hh index afd5cc328..ff188b654 100644 --- a/src/tgba/taatgba.hh +++ b/src/tgba/taatgba.hh @@ -159,18 +159,6 @@ namespace spot public: taa_tgba_labelled(bdd_dict* dict) : taa_tgba(dict) {}; - virtual ~taa_tgba_labelled() - { - typename ns_map::iterator i; - for (i = name_state_map_.begin(); i != name_state_map_.end(); ++i) - { - taa_tgba::state::iterator i2; - for (i2 = i->second->begin(); i2 != i->second->end(); ++i2) - delete *i2; - delete i->second; - } - } - void set_init_state(const label& s) { std::vector