From a1734e3051acc958ef5ef29b86d39d1a772c921e Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Fri, 16 Jan 2015 08:40:19 +0100 Subject: [PATCH] Fix deadlock in VMOps::For fixes #8236 --- lib/config/vmops.hpp | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/lib/config/vmops.hpp b/lib/config/vmops.hpp index 91663a1c5..cb5f3e508 100644 --- a/lib/config/vmops.hpp +++ b/lib/config/vmops.hpp @@ -137,19 +137,8 @@ public: Array::Ptr arr = value; - ObjectLock olock(arr); - BOOST_FOREACH(const Value& value, arr) { - frame.Locals->Set(fkvar, value); - expression->Evaluate(frame); - } - } else if (value.IsString()) { - if (!fvvar.IsEmpty()) - BOOST_THROW_EXCEPTION(ScriptError("Cannot use dictionary iterator for string.", debugInfo)); - - String str = value; - - BOOST_FOREACH(char ch, str) { - frame.Locals->Set(fkvar, String(1, ch)); + for (Array::SizeType i = 0; i < arr->GetLength(); i++) { + frame.Locals->Set(fkvar, arr->Get(i)); expression->Evaluate(frame); } } else if (value.IsObjectType()) { @@ -157,11 +146,18 @@ public: BOOST_THROW_EXCEPTION(ScriptError("Cannot use array iterator for dictionary.", debugInfo)); Dictionary::Ptr dict = value; + std::vector keys; + + { + ObjectLock olock(dict); + BOOST_FOREACH(const Dictionary::Pair& kv, dict) { + keys.push_back(kv.first); + } + } - ObjectLock olock(dict); - BOOST_FOREACH(const Dictionary::Pair& kv, dict) { - frame.Locals->Set(fkvar, kv.first); - frame.Locals->Set(fvvar, kv.second); + BOOST_FOREACH(const String& key, keys) { + frame.Locals->Set(fkvar, key); + frame.Locals->Set(fvvar, dict->Get(key)); expression->Evaluate(frame); } } else -- 2.40.0