[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [kgpg] core: rework the tracking if KGpgRootNode is currently deleting
From:       Rolf Eike Beer <kde () opensource ! sf-tec ! de>
Date:       2016-10-11 16:21:28
Message-ID: E1btzo0-000785-Fr () code ! kde ! org
[Download RAW message or body]

Git commit 0499dca3914633d1ece028a187a1c8fa22d9422d by Rolf Eike Beer.
Committed on 11/10/2016 at 16:16.
Pushed by dakon into branch 'master'.

rework the tracking if KGpgRootNode is currently deleting

When the destructor is called the child objects may not do calls into the
functions of this object anymore. Tell them in advance that the root node is
going away so they do not even try.

M  +2    -4    core/KGpgGroupNode.cpp
M  +3    -1    core/KGpgKeyNode.cpp
M  +2    -2    core/KGpgNode.cpp
M  +5    -21   core/KGpgRootNode.cpp
M  +0    -14   core/KGpgRootNode.h

http://commits.kde.org/kgpg/0499dca3914633d1ece028a187a1c8fa22d9422d

diff --git a/core/KGpgGroupNode.cpp b/core/KGpgGroupNode.cpp
index 2a0cb2b..b5de9b8 100644
--- a/core/KGpgGroupNode.cpp
+++ b/core/KGpgGroupNode.cpp
@@ -140,10 +140,8 @@ KGpgGroupNode::KGpgGroupNode(KGpgRootNode *parent, const QString &name, const KG
 
 KGpgGroupNode::~KGpgGroupNode()
 {
-	KGpgRootNode *root = m_parent->toRootNode();
-
-	if (root != Q_NULLPTR)
-		root->m_groups--;
+	if (parent() != Q_NULLPTR)
+		m_parent->toRootNode()->m_groups--;
 }
 
 KgpgCore::KgpgItemType
diff --git a/core/KGpgKeyNode.cpp b/core/KGpgKeyNode.cpp
index e509ab9..3737bd9 100644
--- a/core/KGpgKeyNode.cpp
+++ b/core/KGpgKeyNode.cpp
@@ -39,8 +39,10 @@ KGpgKeyNode::KGpgKeyNode(KGpgRootNode *parent, const KgpgCore::KgpgKey &k)
 
 KGpgKeyNode::~KGpgKeyNode()
 {
+	// do not try to access the root node if we are being deleted from there
+	KGpgRootNode * const root = parent() != Q_NULLPTR ? m_parent->toRootNode() : Q_NULLPTR;
 	foreach (KGpgRefNode *nd, m_refs) {
-		nd->unRef(m_parent->toRootNode());
+		nd->unRef(root);
 	}
 }
 
diff --git a/core/KGpgNode.cpp b/core/KGpgNode.cpp
index 5c9605e..905812a 100644
--- a/core/KGpgNode.cpp
+++ b/core/KGpgNode.cpp
@@ -113,7 +113,7 @@ KGpgNode::toRootNode()
 {
 	Q_ASSERT((m_parent == Q_NULLPTR) && (getType() == 0));
 
-	return static_cast<KGpgRootNode *>(this)->asRootNode();
+	return static_cast<KGpgRootNode *>(this);
 }
 
 const KGpgRootNode *
@@ -121,7 +121,7 @@ KGpgNode::toRootNode() const
 {
 	Q_ASSERT((m_parent == Q_NULLPTR) && (getType() == 0));
 
-	return static_cast<const KGpgRootNode *>(this)->asRootNode();
+	return static_cast<const KGpgRootNode *>(this);
 }
 
 KGpgUidNode *
diff --git a/core/KGpgRootNode.cpp b/core/KGpgRootNode.cpp
index 7a27661..cd464d8 100644
--- a/core/KGpgRootNode.cpp
+++ b/core/KGpgRootNode.cpp
@@ -28,15 +28,17 @@
 
 KGpgRootNode::KGpgRootNode(KGpgItemModel *model)
 	: KGpgExpandableNode(Q_NULLPTR),
-	m_groups(0),
-	m_deleting(false)
+	m_groups(0)
 {
 	m_model = model;
 }
 
 KGpgRootNode::~KGpgRootNode()
 {
-	m_deleting = true;
+	// clear the parents in all children to signal them not to do any
+	// update signalling
+	for (KGpgNode *child: children)
+		child->setParent(Q_NULLPTR);
 }
 
 void
@@ -161,21 +163,3 @@ KGpgRootNode::findKeyRow(const KGpgKeyNode *key)
 	}
 	return -1;
 }
-
-KGpgRootNode *
-KGpgRootNode::asRootNode()
-{
-	if (m_deleting)
-		return Q_NULLPTR;
-
-	return this;
-}
-
-const KGpgRootNode *
-KGpgRootNode::asRootNode() const
-{
-	if (m_deleting)
-		return Q_NULLPTR;
-
-	return this;
-}
diff --git a/core/KGpgRootNode.h b/core/KGpgRootNode.h
index f75ad05..698b59a 100644
--- a/core/KGpgRootNode.h
+++ b/core/KGpgRootNode.h
@@ -44,7 +44,6 @@ class KGpgRootNode : public KGpgExpandableNode
 
 private:
 	int m_groups;
-	int m_deleting;
 
 protected:
 	virtual void readChildren() Q_DECL_OVERRIDE;
@@ -110,19 +109,6 @@ public:
 	 */
 	int groupChildren() const;
 
-	/**
-	 * Return a pointer to this object or Q_NULLPTR
-	 *
-	 * This returns a pointer to this object if the object will persist,
-	 * i.e. is not currently in destruction. If the object is already
-	 * cleaning up Q_NULLPTR is returned.
-	 */
-	KGpgRootNode *asRootNode();
-	/**
-	 * @overload
-	 */
-	const KGpgRootNode *asRootNode() const;
-
 Q_SIGNALS:
 	void newKeyNode(KGpgKeyNode *);
 };

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic