From 477d177b5a6b1fb0b8bbf97a829286b3b48ecf02 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Tue, 15 Nov 2022 12:51:13 +0100 Subject: [PATCH] Cache locals of script frame used for group assign where eval to avoid malloc(). This BREAKS assign where locals.x = 1. --- lib/icinga/hostgroup.cpp | 18 ++++++++++++++---- lib/icinga/servicegroup.cpp | 19 +++++++++++++------ 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/lib/icinga/hostgroup.cpp b/lib/icinga/hostgroup.cpp index 9ab338300..d1d88dac0 100644 --- a/lib/icinga/hostgroup.cpp +++ b/lib/icinga/hostgroup.cpp @@ -24,10 +24,20 @@ bool HostGroup::EvaluateObjectRule(const Host::Ptr& host, const ConfigItem::Ptr& CONTEXT("Evaluating rule for group '" << groupName << "'"); - ScriptFrame frame(true); - if (group->GetScope()) - group->GetScope()->CopyTo(frame.Locals); - frame.Locals->Set("host", host); + ScriptFrame frame (false); + + if (group->GetScope()) { + frame.Locals = new Dictionary(); + + if (group->GetScope()) { + group->GetScope()->CopyTo(frame.Locals); + } + + host->GetFrozenLocalsForApply()->CopyTo(frame.Locals); + frame.Locals->Freeze(); + } else { + frame.Locals = host->GetFrozenLocalsForApply(); + } if (!group->GetFilter()->Evaluate(frame).GetValue().ToBool()) return false; diff --git a/lib/icinga/servicegroup.cpp b/lib/icinga/servicegroup.cpp index ee2bc9c6e..f3c689446 100644 --- a/lib/icinga/servicegroup.cpp +++ b/lib/icinga/servicegroup.cpp @@ -24,13 +24,20 @@ bool ServiceGroup::EvaluateObjectRule(const Service::Ptr& service, const ConfigI CONTEXT("Evaluating rule for group '" << groupName << "'"); - Host::Ptr host = service->GetHost(); + ScriptFrame frame (false); - ScriptFrame frame(true); - if (group->GetScope()) - group->GetScope()->CopyTo(frame.Locals); - frame.Locals->Set("host", host); - frame.Locals->Set("service", service); + if (group->GetScope()) { + frame.Locals = new Dictionary(); + + if (group->GetScope()) { + group->GetScope()->CopyTo(frame.Locals); + } + + service->GetFrozenLocalsForApply()->CopyTo(frame.Locals); + frame.Locals->Freeze(); + } else { + frame.Locals = service->GetFrozenLocalsForApply(); + } if (!group->GetFilter()->Evaluate(frame).GetValue().ToBool()) return false;