From 3a7bce693eae351386d55e5e7076144dfc95c2a6 Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Thu, 26 Nov 2020 20:41:20 +0200 Subject: [PATCH] Explicitly destroy plugins A plugin may need to access kwinApp() or kwinApp()->platform() during tear down, but the problem is that plugins are destroyed after the kwinApp() object. The plugin manager must be destroyed explicitly while the application is still valid to ensure that no crash will occur during compositor teardown. --- autotests/integration/kwin_wayland_test.cpp | 3 ++- main.cpp | 11 +++++++++++ main.h | 2 ++ main_wayland.cpp | 4 ++-- main_x11.cpp | 4 ++-- 5 files changed, 19 insertions(+), 5 deletions(-) diff --git a/autotests/integration/kwin_wayland_test.cpp b/autotests/integration/kwin_wayland_test.cpp index 99fddee84b..a888f7b33d 100644 --- a/autotests/integration/kwin_wayland_test.cpp +++ b/autotests/integration/kwin_wayland_test.cpp @@ -79,6 +79,7 @@ WaylandTestApplication::~WaylandTestApplication() if (effects) { static_cast(effects)->unloadAllEffects(); } + destroyPlugins(); delete m_xwayland; m_xwayland = nullptr; destroyWorkspace(); @@ -131,7 +132,7 @@ void WaylandTestApplication::performStartup() // try creating the Wayland Backend createInput(); createBackend(); - PluginManager::create(this); + createPlugins(); } void WaylandTestApplication::createBackend() diff --git a/main.cpp b/main.cpp index c6c13f77f3..403fac3ae9 100644 --- a/main.cpp +++ b/main.cpp @@ -17,6 +17,7 @@ #include "input.h" #include "logind.h" #include "options.h" +#include "pluginmanager.h" #include "screens.h" #include "screenlockerwatcher.h" #include "sm.h" @@ -296,6 +297,11 @@ void Application::createOptions() options = new Options; } +void Application::createPlugins() +{ + PluginManager::create(this); +} + void Application::installNativeX11EventFilter() { installNativeEventFilter(m_eventFilter.data()); @@ -316,6 +322,11 @@ void Application::destroyCompositor() delete Compositor::self(); } +void Application::destroyPlugins() +{ + delete PluginManager::self(); +} + void Application::updateX11Time(xcb_generic_event_t *event) { xcb_timestamp_t time = XCB_TIME_CURRENT_TIME; diff --git a/main.h b/main.h index 4f4409fa56..e2a9c562de 100644 --- a/main.h +++ b/main.h @@ -210,10 +210,12 @@ protected: void createWorkspace(); void createAtoms(); void createOptions(); + void createPlugins(); void installNativeX11EventFilter(); void removeNativeX11EventFilter(); void destroyWorkspace(); void destroyCompositor(); + void destroyPlugins(); /** * Inheriting classes should use this method to set the X11 root window * before accessing any X11 specific code pathes. diff --git a/main_wayland.cpp b/main_wayland.cpp index 216dda0d5d..184ca65a2c 100644 --- a/main_wayland.cpp +++ b/main_wayland.cpp @@ -14,7 +14,6 @@ // kwin #include "platform.h" #include "effects.h" -#include "pluginmanager.h" #include "tabletmodemanager.h" #include "wayland_server.h" @@ -129,6 +128,7 @@ ApplicationWayland::~ApplicationWayland() if (effects) { static_cast(effects)->unloadAllEffects(); } + destroyPlugins(); delete m_xwayland; m_xwayland = nullptr; destroyWorkspace(); @@ -158,7 +158,7 @@ void ApplicationWayland::performStartup() InputMethod::create(this); createBackend(); TabletModeManager::create(this); - PluginManager::create(this); + createPlugins(); } void ApplicationWayland::createBackend() diff --git a/main_x11.cpp b/main_x11.cpp index 32d27a4637..ee23fdf40b 100644 --- a/main_x11.cpp +++ b/main_x11.cpp @@ -13,7 +13,6 @@ #include #include "platform.h" -#include "pluginmanager.h" #include "sm.h" #include "workspace.h" #include "xcbutils.h" @@ -191,6 +190,7 @@ void ApplicationX11::setReplace(bool replace) void ApplicationX11::lostSelection() { sendPostedEvents(); + destroyPlugins(); destroyCompositor(); destroyWorkspace(); // Remove windowmanager privileges @@ -249,7 +249,7 @@ void ApplicationX11::performStartup() connect(platform(), &Platform::screensQueried, this, [this] { createWorkspace(); - PluginManager::create(this); + createPlugins(); Xcb::sync(); // Trigger possible errors, there's still a chance to abort