From 81ea546dc6b4faa93a314624456f73babab06596 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Wed, 6 Oct 2021 23:25:19 +0300 Subject: [PATCH] Avoid inconsistent state in Collection if a notify function throws --- source/collection.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) 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) -- 2.45.2