From baac61b8e5b9b6cd8af99b8bee523ee15858f1dc Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Mon, 3 Apr 2023 11:12:13 +0300 Subject: [PATCH] Fix calling virtual methods in Window destructor When a window is removed from the deleted list, some effects can perform cleanup. In its turn, it means that they can call some Window methods. If those methods happen to be virtual, kwin can crash because calling virtual methods in the destructor of a base class has undefined behavior. --- src/window.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/window.cpp b/src/window.cpp index d936696c9f..abad641f07 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -104,9 +104,6 @@ Window::Window() Window::~Window() { - if (m_deleted) { - workspace()->removeDeleted(this); - } if (m_tile) { m_tile->removeWindow(this); } @@ -121,9 +118,13 @@ void Window::ref() void Window::unref() { --m_refCount; - if (m_refCount == 0) { - delete this; + if (m_refCount) { + return; } + if (m_deleted) { + workspace()->removeDeleted(this); + } + delete this; } QDebug operator<<(QDebug debug, const Window *window)