From fba52f75b6c081752a56bedfae0295aae78ecbaf Mon Sep 17 00:00:00 2001 From: Robert Knight Date: Thu, 21 Feb 2008 23:23:22 +0000 Subject: [PATCH] Forward port fix for #158131. Fix crash when removing actions owned by an invalid controller. BUG: 158131 svn path=/trunk/KDE/kdebase/apps/konsole/; revision=777943 --- src/MainWindow.cpp | 9 ++++++++- src/SessionController.h | 12 ++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 483db2098..9bc7e4866 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -133,7 +133,14 @@ void MainWindow::disconnectController(SessionController* controller) { disconnect( controller , SIGNAL(titleChanged(ViewProperties*)) , this , SLOT(activeViewTitleChanged(ViewProperties*)) ); - guiFactory()->removeClient(controller); + + // KXmlGuiFactory::removeClient() will try to access actions associated + // with the controller internally, which may not be valid after the controller + // itself is no longer valid (after the associated session and or view have + // been destroyed) + if (controller->isValid()) + guiFactory()->removeClient(controller); + controller->setSearchBar(0); } diff --git a/src/SessionController.h b/src/SessionController.h index cc9e356cc..fad71e9f0 100644 --- a/src/SessionController.h +++ b/src/SessionController.h @@ -95,6 +95,14 @@ public: QPointer session() { return _session; } /** Returns the view associated with this controller */ QPointer view() { return _view; } + + /** + * Returns true if the controller is valid. + * A valid controller is one which has a non-null session() and view(). + * + * Equivalent to "!session().isNull() && !view().isNull()" + */ + bool isValid() const; /** * Sets the widget used for searches through the session's output. @@ -250,6 +258,10 @@ private: bool _listenForScreenWindowUpdates; bool _preventClose; }; +inline bool SessionController::isValid() const +{ + return !_session.isNull() && !_view.isNull(); +} /** * Abstract class representing a task which can be performed on a group of sessions.