[icinga-checkins] icinga.org: icinga2/fix/dependency-graph-crash: Make sure objects are removed from the dependency graph

git at icinga.org git at icinga.org
Mon May 9 13:16:22 CEST 2016


Module: icinga2
Branch: fix/dependency-graph-crash
Commit: 7124de9fc842499ae78f55302e85e5bdaf45018d
URL:    https://git.icinga.org/?p=icinga2.git;a=commit;h=7124de9fc842499ae78f55302e85e5bdaf45018d

Author: Gunnar Beutner <gunnar.beutner at netways.de>
Date:   Mon May  9 13:16:00 2016 +0200

Make sure objects are removed from the dependency graph

---

 lib/base/configtype.cpp      |    3 +++
 lib/base/dependencygraph.cpp |   15 +++++++++++++++
 lib/base/dependencygraph.hpp |    1 +
 3 files changed, 19 insertions(+)

diff --git a/lib/base/configtype.cpp b/lib/base/configtype.cpp
index bc1ea41..697738d 100644
--- a/lib/base/configtype.cpp
+++ b/lib/base/configtype.cpp
@@ -23,6 +23,7 @@
 #include "base/objectlock.hpp"
 #include "base/convert.hpp"
 #include "base/exception.hpp"
+#include "base/dependencygraph.hpp"
 
 using namespace icinga;
 
@@ -115,6 +116,8 @@ void ConfigType::UnregisterObject(const ConfigObject::Ptr& object)
 {
 	String name = object->GetName();
 
+	DependencyGraph::RemoveAllDependencies(object.get());
+
 	{
 		ObjectLock olock(this);
 
diff --git a/lib/base/dependencygraph.cpp b/lib/base/dependencygraph.cpp
index 6f1053c..617d1b7 100644
--- a/lib/base/dependencygraph.cpp
+++ b/lib/base/dependencygraph.cpp
@@ -37,6 +37,21 @@ void DependencyGraph::RemoveDependency(Object *parent, Object *child)
 	m_Dependencies[child][parent]--;
 }
 
+void DependencyGraph::RemoveAllDependencies(Object *parent)
+{
+	boost::mutex::scoped_lock lock(m_Mutex);
+
+	typedef std::map<Object *, std::map<Object *, int> >::value_type kv_pair;
+	BOOST_FOREACH(kv_pair& kv, m_Dependencies) {
+		std::map<Object *, int>::iterator it = kv.second.find(parent);
+
+		if (it == kv.second.end())
+			continue;
+
+		it->second--;
+	}
+}
+
 std::vector<Object::Ptr> DependencyGraph::GetParents(const Object::Ptr& child)
 {
 	std::vector<Object::Ptr> objects;
diff --git a/lib/base/dependencygraph.hpp b/lib/base/dependencygraph.hpp
index 58dc33b..f1a02df 100644
--- a/lib/base/dependencygraph.hpp
+++ b/lib/base/dependencygraph.hpp
@@ -36,6 +36,7 @@ class I2_BASE_API DependencyGraph
 public:
 	static void AddDependency(Object *parent, Object *child);
 	static void RemoveDependency(Object *parent, Object *child);
+	static void RemoveAllDependencies(Object *parent);
 	static std::vector<Object::Ptr> GetParents(const Object::Ptr& child);
 
 private:



More information about the icinga-checkins mailing list