From 9630e869978f165df798db6e76d2be5718231200 Mon Sep 17 00:00:00 2001 From: Julian Brost Date: Wed, 9 Mar 2022 14:29:44 +0100 Subject: [PATCH] Add missing array locking in IcingaDB::GetArrayDeletedValues() icinga::Array requires locking by the caller when iterating using Begin() and End(). This is only checked in debug builds but there it makes this function fail. --- lib/icingadb/icingadb-utility.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/icingadb/icingadb-utility.cpp b/lib/icingadb/icingadb-utility.cpp index f82625019..bb24e0314 100644 --- a/lib/icingadb/icingadb-utility.cpp +++ b/lib/icingadb/icingadb-utility.cpp @@ -266,14 +266,23 @@ std::vector IcingaDB::GetArrayDeletedValues(const Array::Ptr& arrayOld, c } if (!arrayNew) { + ObjectLock olock (arrayOld); return std::vector(arrayOld->Begin(), arrayOld->End()); } - std::vector vectorOld(arrayOld->Begin(), arrayOld->End()); + std::vector vectorOld; + { + ObjectLock olock (arrayOld); + vectorOld.assign(arrayOld->Begin(), arrayOld->End()); + } std::sort(vectorOld.begin(), vectorOld.end()); vectorOld.erase(std::unique(vectorOld.begin(), vectorOld.end()), vectorOld.end()); - std::vector vectorNew(arrayNew->Begin(), arrayNew->End()); + std::vector vectorNew; + { + ObjectLock olock (arrayNew); + vectorNew.assign(arrayNew->Begin(), arrayNew->End()); + } std::sort(vectorNew.begin(), vectorNew.end()); vectorNew.erase(std::unique(vectorNew.begin(), vectorNew.end()), vectorNew.end());