]> granicus.if.org Git - icinga2/commitdiff
Fix incorrect debug hints for nested attributes
authorGunnar Beutner <gunnar@beutner.name>
Thu, 5 Mar 2015 12:18:15 +0000 (13:18 +0100)
committerGunnar Beutner <gunnar@beutner.name>
Thu, 5 Mar 2015 12:18:15 +0000 (13:18 +0100)
fixes #8604

lib/config/expression.cpp
lib/config/expression.hpp

index 6e8b182033988fe24140c64e38f97707043b6531..7350a97ae9a27210e4caeb9b7b7c18ade44a0aff 100644 (file)
@@ -598,12 +598,17 @@ bool IndexerExpression::GetReference(ScriptFrame& frame, bool init_dict, Value *
        Value vparent;
        String vindex;
        DebugHint *psdhint = NULL;
+       bool free_psd = false;
+
+       if (dhint)
+               psdhint = *dhint;
 
        if (m_Operand1->GetReference(frame, init_dict, &vparent, &vindex, &psdhint)) {
                if (init_dict && VMOps::GetField(vparent, vindex, m_Operand1->GetDebugInfo()).IsEmpty())
                        VMOps::SetField(vparent, vindex, new Dictionary(), m_Operand1->GetDebugInfo());
 
                *parent = VMOps::GetField(vparent, vindex, m_DebugInfo);
+               free_psd = true;
        } else {
                ExpressionResult operand1 = m_Operand1->Evaluate(frame);
                *parent = operand1.GetValue();
@@ -615,7 +620,8 @@ bool IndexerExpression::GetReference(ScriptFrame& frame, bool init_dict, Value *
        if (dhint && psdhint)
                *dhint = new DebugHint(psdhint->GetChild(*index));
 
-       delete psdhint;
+       if (free_psd)
+               delete psdhint;
 
        return true;
 }
index 0180c2be978a487c7279b7eb58880e3705cbb2cf..6f7dbfe53b43bb3b5259722a0955aeac2427a0e7 100644 (file)
@@ -44,14 +44,6 @@ public:
 
        inline void AddMessage(const String& message, const DebugInfo& di)
        {
-               if (!m_Hints)
-                       m_Hints = new Dictionary();
-
-               if (!m_Messages) {
-                       m_Messages = new Array();
-                       m_Hints->Set("messages", m_Messages);
-               }
-
                Array::Ptr amsg = new Array();
                amsg->Add(message);
                amsg->Add(di.Path);
@@ -59,24 +51,18 @@ public:
                amsg->Add(di.FirstColumn);
                amsg->Add(di.LastLine);
                amsg->Add(di.LastColumn);
-               m_Messages->Add(amsg);
+               GetMessages()->Add(amsg);
        }
 
        inline DebugHint GetChild(const String& name)
        {
-               if (!m_Hints)
-                       m_Hints = new Dictionary();
+               Dictionary::Ptr children = GetChildren();
 
-               if (!m_Children) {
-                       m_Children = new Dictionary;
-                       m_Hints->Set("properties", m_Children);
-               }
-
-               Dictionary::Ptr child = m_Children->Get(name);
+               Dictionary::Ptr child = children->Get(name);
 
                if (!child) {
                        child = new Dictionary();
-                       m_Children->Set(name, child);
+                       children->Set(name, child);
                }
 
                return DebugHint(child);
@@ -89,8 +75,36 @@ public:
 
 private:
        Dictionary::Ptr m_Hints;
-       Array::Ptr m_Messages;
-       Dictionary::Ptr m_Children;
+
+       Array::Ptr GetMessages(void)
+       {
+               if (!m_Hints)
+                       m_Hints = new Dictionary();
+
+               Array::Ptr messages = m_Hints->Get("messages");
+
+               if (!messages) {
+                       messages = new Array();
+                       m_Hints->Set("messages", messages);
+               }
+
+               return messages;
+       }
+
+       Dictionary::Ptr GetChildren(void)
+       {
+               if (!m_Hints)
+                       m_Hints = new Dictionary();
+
+               Dictionary::Ptr children = m_Hints->Get("properties");
+
+               if (!children) {
+                       children = new Dictionary;
+                       m_Hints->Set("properties", children);
+               }
+
+               return children;
+       }
 };
 
 enum CombinedSetOp