]> granicus.if.org Git - icinga2/commitdiff
Fix failed assertion in ScriptUtils::Intersection
authorGunnar Beutner <gunnar@beutner.name>
Wed, 15 Jul 2015 06:19:55 +0000 (08:19 +0200)
committerGunnar Beutner <gunnar@beutner.name>
Wed, 15 Jul 2015 06:20:16 +0000 (08:20 +0200)
fixes #9621

lib/base/scriptutils.cpp

index e51430cce5ae13d476e047de6724fa873e9f38d6..3c4caff6a80db567a4159eb13a839dc8c4db57b8 100644 (file)
@@ -138,7 +138,10 @@ Array::Ptr ScriptUtils::Intersection(const std::vector<Value>& arguments)
        Array::Ptr arr1 = arg1->ShallowClone();
 
        for (std::vector<Value>::size_type i = 1; i < arguments.size(); i++) {
-               std::sort(arr1->Begin(), arr1->End());
+               {
+                       ObjectLock olock(arr1);
+                       std::sort(arr1->Begin(), arr1->End());
+               }
 
                Array::Ptr arg2 = arguments[i];
 
@@ -146,11 +149,19 @@ Array::Ptr ScriptUtils::Intersection(const std::vector<Value>& arguments)
                        return result;
 
                Array::Ptr arr2 = arg2->ShallowClone();
-               std::sort(arr2->Begin(), arr2->End());
+               {
+                       ObjectLock olock(arr2);
+                       std::sort(arr2->Begin(), arr2->End());
+               }
 
                result->Resize(std::max(arr1->GetLength(), arr2->GetLength()));
-               Array::Iterator it = std::set_intersection(arr1->Begin(), arr1->End(), arr2->Begin(), arr2->End(), result->Begin());
-               result->Resize(it - result->Begin());
+               Array::SizeType len;
+               {
+                       ObjectLock olock(arr1), xlock(arr2), ylock(result);
+                       Array::Iterator it = std::set_intersection(arr1->Begin(), arr1->End(), arr2->Begin(), arr2->End(), result->Begin());
+                       len = it - result->Begin();
+               }
+               result->Resize(len);
                arr1 = result;
        }