From: Mikko Rasa Date: Wed, 6 Oct 2021 20:25:19 +0000 (+0300) Subject: Avoid inconsistent state in Collection if a notify function throws X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=81ea546dc6b4faa93a314624456f73babab06596;p=libs%2Fdatafile.git Avoid inconsistent state in Collection if a notify function throws --- diff --git a/source/collection.cpp b/source/collection.cpp index 8b29585..d222568 100644 --- a/source/collection.cpp +++ b/source/collection.cpp @@ -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)