[icinga-checkins] icinga.org: icinga2/master: Bugfixes: Finalizing the interpreter might crash.

git at icinga.org git at icinga.org
Thu Feb 14 15:52:05 CET 2013


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

Author: Gunnar Beutner <gunnar.beutner at netways.de>
Date:   Thu Feb 14 15:51:50 2013 +0100

Bugfixes: Finalizing the interpreter might crash.

---

 lib/python/pythoninterpreter.cpp |    8 ++++----
 lib/python/pythonlanguage.cpp    |    4 +++-
 2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/lib/python/pythoninterpreter.cpp b/lib/python/pythoninterpreter.cpp
index b4f0e3f..63f31e0 100644
--- a/lib/python/pythoninterpreter.cpp
+++ b/lib/python/pythoninterpreter.cpp
@@ -29,11 +29,11 @@ PythonInterpreter::PythonInterpreter(const PythonLanguage::Ptr& language, const
 	PyInterpreterState *interp = m_Language->GetMainThreadState()->interp;
 	m_ThreadState = PyThreadState_New(interp);
 
-	PyEval_ReleaseLock();
-
-	PyEval_AcquireThread(m_ThreadState);
+	(void) PyThreadState_Swap(m_ThreadState);
 	PyRun_SimpleString(script->GetCode().CStr());
-	PyEval_ReleaseThread(m_ThreadState);
+	(void) PyThreadState_Swap(m_Language->GetMainThreadState());
+
+	PyEval_ReleaseLock();
 }
 
 PythonInterpreter::~PythonInterpreter(void)
diff --git a/lib/python/pythonlanguage.cpp b/lib/python/pythonlanguage.cpp
index 5226081..b933159 100644
--- a/lib/python/pythonlanguage.cpp
+++ b/lib/python/pythonlanguage.cpp
@@ -40,7 +40,9 @@ PythonLanguage::PythonLanguage(void)
 
 PythonLanguage::~PythonLanguage(void)
 {
-	Py_Finalize();
+	/* Due to how we're destructing objects it might not be safe to
+	 * call Py_Finalize() when the Icinga instance is being shut
+	 * down - so don't bother calling it. */
 }
 
 ScriptInterpreter::Ptr PythonLanguage::CreateInterpreter(const Script::Ptr& script)





More information about the icinga-checkins mailing list