From a19f337a0c9e120b0f6101e6df71e2ebfc3a9b9d Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sun, 16 Sep 2007 04:03:50 +0000 Subject: Changed ManagedList to make it more thread safe svn-id: r28914 --- engines/lure/res_struct.h | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/engines/lure/res_struct.h b/engines/lure/res_struct.h index f6c1966a93..81ecd87563 100644 --- a/engines/lure/res_struct.h +++ b/engines/lure/res_struct.h @@ -254,23 +254,28 @@ public: } void clear() { - typename Common::List::iterator i; - for (i = Common_List::begin(); i != Common_List::end(); ++i) - delete *i; - Common_List::clear(); + typename Common_List::iterator i = Common_List::begin(); + while (i != Common_List::end()) { + T v = *i; + i = Common_List::erase(i); + delete v; + } } - typename Common::List::iterator erase(typename Common::List::iterator pos) { - delete *pos; - return Common_List::erase(pos); + typename Common_List::iterator erase(typename Common_List::iterator pos) { + T obj = *pos; + typename Common_List::iterator result = Common_List::erase(pos); + delete obj; + return result; } - typename Common::List::iterator erase(typename Common::List::iterator first, - typename Common::List::iterator last) { - typename Common::List::iterator i; - for (i = first; i != last; ++i) - delete *i; - return Common_List::erase(first, last); + typename Common_List::iterator erase(typename Common_List::iterator first, + typename Common_List::iterator last) { + + while (first != last) + erase(first++); + + return last; } }; -- cgit v1.2.3