]> git.tdb.fi Git - libs/datafile.git/commitdiff
Avoid inconsistent state in Collection if a notify function throws
authorMikko Rasa <tdb@tdb.fi>
Wed, 6 Oct 2021 20:25:19 +0000 (23:25 +0300)
committerMikko Rasa <tdb@tdb.fi>
Wed, 6 Oct 2021 20:25:19 +0000 (23:25 +0300)
source/collection.cpp

index 8b295858ac72fadf42a535be78c7272d8e50ba27..d222568403355f4f3af1b1b0896a27f9311c7696 100644 (file)
@@ -20,8 +20,16 @@ Collection::~Collection()
 void Collection::add_var(const string &name, const CollectionItemTypeBase *type, const Variant &var)
 {
        insert_unique(items, name, var);
-       if(type)
-               type->notify_item(name, var);
+       try
+       {
+               if(type)
+                       type->notify_item(name, var);
+       }
+       catch(...)
+       {
+               remove_existing(items, name);
+               throw;
+       }
 }
 
 const Variant &Collection::get_var(const string &name, const CollectionItemTypeBase *type)