From 01d8907ea9a9a2866f35a18ae1473ae5ebbb1424 Mon Sep 17 00:00:00 2001
From: Adam Treat <atreat@rim.com>
Date: Fri, 27 Jan 2012 07:52:03 -0500
Subject: [PATCH] Fix a crash when loading the qt4projectmangerplugin.

This crash can happen when enabling/disabling a certain combination
of plugins and restarting.

There was a null pointer de-reference that was occurring because the
qt4projectmanagerplugin was referencing an action that it believed
to have been registered by the texteditorplugin when it was initialized.

However, apparently the texteditorplugin was not initializing its actions
at plugin initialization, but rather when 'extensionsInitialized' was called.
I do not know the call graph for when this is to be called, but I encountered
at least one situation where the qt4projectmanagerplugin was being initialized
before this.

Change-Id: Iede1831e0ac9c92b80a079157e1bdc8c66473470
Reviewed-by: Leandro Melo <leandro.melo@nokia.com>
Reviewed-by: Eike Ziller <eike.ziller@nokia.com>
---
 src/plugins/coreplugin/actionmanager/actioncontainer.cpp | 2 +-
 src/plugins/texteditor/texteditorplugin.cpp              | 7 +++++--
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/src/plugins/coreplugin/actionmanager/actioncontainer.cpp b/src/plugins/coreplugin/actionmanager/actioncontainer.cpp
index d6a47d3adb6..30896c45f69 100644
--- a/src/plugins/coreplugin/actionmanager/actioncontainer.cpp
+++ b/src/plugins/coreplugin/actionmanager/actioncontainer.cpp
@@ -330,7 +330,7 @@ QMenuBar *ActionContainerPrivate::menuBar() const
 
 bool ActionContainerPrivate::canAddAction(Command *action) const
 {
-    return (action->action() != 0);
+    return action && action->action();
 }
 
 void ActionContainerPrivate::scheduleUpdate()
diff --git a/src/plugins/texteditor/texteditorplugin.cpp b/src/plugins/texteditor/texteditorplugin.cpp
index 1dc6300f827..da996004e4f 100644
--- a/src/plugins/texteditor/texteditorplugin.cpp
+++ b/src/plugins/texteditor/texteditorplugin.cpp
@@ -163,13 +163,16 @@ bool TextEditorPlugin::initialize(const QStringList &arguments, QString *errorMe
     m_outlineFactory = new OutlineFactory;
     addAutoReleasedObject(m_outlineFactory);
 
+    // We have to initialize the actions because other plugins that
+    // depend upon the texteditorplugin expect that actions will be
+    // registered in the action manager at plugin initialization time.
+    m_editorFactory->actionHandler()->initializeActions();
+
     return true;
 }
 
 void TextEditorPlugin::extensionsInitialized()
 {
-    m_editorFactory->actionHandler()->initializeActions();
-
     ExtensionSystem::PluginManager *pluginManager = ExtensionSystem::PluginManager::instance();
 
     m_searchResultWindow = Find::SearchResultWindow::instance();
-- 
GitLab