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

List:       kde-commits
Subject:    [kdev-cppcheck] /: Fix crash after plugin unloading
From:       Anton Anikin <anton.anikin () htower ! ru>
Date:       2016-10-17 3:57:00
Message-ID: E1bvz2q-0004BV-9F () code ! kde ! org
[Download RAW message or body]

Git commit 1496d2f6216b7fc8388cf5136cdcad53f1fd0d47 by Anton Anikin.
Committed on 17/10/2016 at 03:56.
Pushed by antonanikin into branch 'master'.

Fix crash after plugin unloading

This commit fixes crash which happens after we unload the plugin and then \
open/close/switch some document/project. The fixed bug was caused by \
"not-disconnected" lambda-function slots.

M  +20   -14   plugin.cpp
M  +1    -0    plugin.h

http://commits.kde.org/kdev-cppcheck/1496d2f6216b7fc8388cf5136cdcad53f1fd0d47

diff --git a/plugin.cpp b/plugin.cpp
index 31d2a62..fcd01d5 100644
--- a/plugin.cpp
+++ b/plugin.cpp
@@ -83,21 +83,15 @@ Plugin::Plugin(QObject* parent, const QVariantList&)
 
     m_actionProjectItem = new QAction("Cppcheck", this);
 
-    auto updateSlot = [this](){ updateActions(); };
+    connect(core()->documentController(), \
&KDevelop::IDocumentController::documentClosed, +            this, \
&Plugin::updateActions); +    connect(core()->documentController(), \
&KDevelop::IDocumentController::documentActivated, +            this, \
&Plugin::updateActions);  
-    connect(core()->documentController(), \
                &KDevelop::IDocumentController::documentClosed,    updateSlot);
-    connect(core()->documentController(), \
                &KDevelop::IDocumentController::documentActivated, updateSlot);
-
-    connect(core()->projectController(), \
&KDevelop::IProjectController::projectOpened, updateSlot); +    \
connect(core()->projectController(), &KDevelop::IProjectController::projectOpened, +  \
                this, &Plugin::updateActions);
     connect(core()->projectController(), \
                &KDevelop::IProjectController::projectClosed,
-            [this](KDevelop::IProject* project) {
-                if (project == m_checkedProject) {
-                    killCppcheck();
-                    m_problems.clear();
-                    m_model->setProblems(m_problems);
-                    m_checkedProject = nullptr;
-                }
-    });
+            this, &Plugin::projectClosed);
 
     ProblemModelSet* pms = core()->languageController()->problemModelSet();
     pms->addModel(modelName, m_model.data());
@@ -163,6 +157,17 @@ void Plugin::updateActions()
     m_actionProject->setEnabled(true);
 }
 
+void Plugin::projectClosed(KDevelop::IProject* project)
+{
+    if (project != m_checkedProject)
+        return;
+
+    killCppcheck();
+    m_problems.clear();
+    m_model->clearProblems();
+    m_checkedProject = nullptr;
+}
+
 void Plugin::runCppcheck(bool checkProject)
 {
     KDevelop::IDocument* doc = core()->documentController()->activeDocument();
@@ -182,6 +187,7 @@ void Plugin::runCppcheck(KDevelop::IProject* project, const \
QString& path)  params.checkPath = path;
 
     m_problems.clear();
+    m_model->clearProblems();
 
     m_job = new Job(params);
 
@@ -223,7 +229,7 @@ void Plugin::result(KJob*)
 {
     if (!core()->projectController()->projects().contains(m_checkedProject)) {
         m_problems.clear();
-        m_model->setProblems(m_problems);
+        m_model->clearProblems();
     } else {
         m_model->setProblems(m_problems);
 
diff --git a/plugin.h b/plugin.h
index 6e6bb82..aa78476 100644
--- a/plugin.h
+++ b/plugin.h
@@ -64,6 +64,7 @@ private:
     void raiseOutputView();
 
     void updateActions();
+    void projectClosed(KDevelop::IProject* project);
 
     void runCppcheck(bool checkProject);
     void runCppcheck(KDevelop::IProject* project, const QString& path);


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

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