From 2f73f948cd2f4bb0bdcc0f5f81816fb169819879 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Tue, 4 Dec 2012 12:28:24 +0200 Subject: [PATCH] Restore the check to avoid deletion if an add call fails It was lost to a careless rewrite in b1bc256. --- source/collection.h | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) 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(); } }; -- 2.45.2