From: Mikko Rasa Date: Tue, 4 Dec 2012 10:28:24 +0000 (+0200) Subject: Restore the check to avoid deletion if an add call fails X-Git-Url: http://git.tdb.fi/?p=libs%2Fdatafile.git;a=commitdiff_plain;h=2f73f948cd2f4bb0bdcc0f5f81816fb169819879 Restore the check to avoid deletion if an add call fails It was lost to a careless rewrite in b1bc256. --- diff --git a/source/collection.h b/source/collection.h index 2243715..6e6900c 100644 --- a/source/collection.h +++ b/source/collection.h @@ -102,7 +102,17 @@ public: if(!item) throw std::invalid_argument("Collection::add(item)"); - insert_unique(items, name, RefPtr::Type>(item)); + RefPtr::Type> ptr(item); + try + { + insert_unique(items, name, ptr); + } + catch(...) + { + // Avoid deleting the object + ptr.release(); + throw; + } } /// Gets a typed object from the collection. @@ -444,8 +454,8 @@ public: RefPtr obj = new T; Collection::ItemLoader ldr(*obj, coll); ldr.load(parser); - // Collection::add will delete the object if it fails - coll.add(name, obj.release()); + coll.add(name, obj.get()); + obj.release(); } };