[icinga-checkins] icinga.org: icinga2/master: Make sure all constructors properly initialize the ScriptFrame object

git at icinga.org git at icinga.org
Fri Aug 12 11:44:42 CEST 2016


Module: icinga2
Branch: master
Commit: 9f67b185b8b99b02273eae81582653a831c8ec79
URL:    https://git.icinga.org/?p=icinga2.git;a=commit;h=9f67b185b8b99b02273eae81582653a831c8ec79

Author: Gunnar Beutner <gunnar.beutner at netways.de>
Date:   Fri Aug 12 11:42:59 2016 +0200

Make sure all constructors properly initialize the ScriptFrame object

refs #12408

---

 lib/base/scriptframe.cpp |   21 ++++++++++++++-------
 lib/base/scriptframe.hpp |    2 ++
 2 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/lib/base/scriptframe.cpp b/lib/base/scriptframe.cpp
index 8c5c7b1..6ea697c 100644
--- a/lib/base/scriptframe.cpp
+++ b/lib/base/scriptframe.cpp
@@ -28,6 +28,17 @@ boost::thread_specific_ptr<std::stack<ScriptFrame *> > ScriptFrame::m_ScriptFram
 ScriptFrame::ScriptFrame(void)
 	: Locals(new Dictionary()), Self(ScriptGlobal::GetGlobals()), Sandboxed(false), Depth(0)
 {
+	InitializeFrame();
+}
+
+ScriptFrame::ScriptFrame(const Value& self)
+	: Locals(new Dictionary()), Self(self), Sandboxed(false), Depth(0)
+{
+	InitializeFrame();
+}
+
+void ScriptFrame::InitializeFrame(void)
+{
 	std::stack<ScriptFrame *> *frames = m_ScriptFrames.get();
 
 	if (frames && !frames->empty()) {
@@ -35,7 +46,9 @@ ScriptFrame::ScriptFrame(void)
 
 		Sandboxed = frame->Sandboxed;
 		Imports = frame->Imports;
-	} else {
+	}
+
+	if (!Imports) {
 		Imports = new Array();
 		Imports->Add(ScriptGlobal::Get("System"));
 	}
@@ -43,12 +56,6 @@ ScriptFrame::ScriptFrame(void)
 	PushFrame(this);
 }
 
-ScriptFrame::ScriptFrame(const Value& self)
-	: Locals(new Dictionary()), Self(self), Sandboxed(false), Depth(0)
-{
-	PushFrame(this);
-}
-
 ScriptFrame::~ScriptFrame(void)
 {
 	ScriptFrame *frame = PopFrame();
diff --git a/lib/base/scriptframe.hpp b/lib/base/scriptframe.hpp
index c0ceb38..9827011 100644
--- a/lib/base/scriptframe.hpp
+++ b/lib/base/scriptframe.hpp
@@ -51,6 +51,8 @@ private:
 
 	inline static void PushFrame(ScriptFrame *frame);
 	inline static ScriptFrame *PopFrame(void);
+
+	void InitializeFrame(void);
 };
 
 }



More information about the icinga-checkins mailing list