Bug 486631

Summary: KWin crashes when accessing window caption while handling Window.visibleGeometryChanged() after workspace.windowRemoved() was triggered
Product: [Plasma] kwin Reporter: Flupp <Flupp+bugs.kde.org>
Component: scriptingAssignee: KWin default assignee <kwin-bugs-null>
Status: RESOLVED NOT A BUG    
Severity: crash CC: nate
Priority: NOR    
Version First Reported In: 6.0.4   
Target Milestone: ---   
Platform: Arch Linux   
OS: Linux   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:
Attachments: Example script triggering a KWin crash. Grep for “potentially triggers KWin crash” to find the guilty line.
backtrace

Description Flupp 2024-05-05 16:52:20 UTC
Created attachment 169216 [details]
Example script triggering a KWin crash. Grep for “potentially triggers KWin crash” to find the guilty line.

Assume a handler function h() is connected to w.visibleGeometryChanged() for a particular window w in a KWin script. Accessing w.caption in h() crashes KWin when workspace.windowRemoved() was already triggered for w.

The issue might be more generic, i.e., accessing a window property after workspace.windowRemoved() was triggered for this window could lead to a KWin crash in general. However, one could ask: Is it a bug of the KWin script to access windows properties of a removed window? Is it expected that KWin scripts can crash KWin (rather than just the script)?


STEPS TO REPRODUCE

The attached KWin script can be used to trigger a crash when a window is removed. Caution: Be prepared to being able to disable the script again to avoid repeated unwanted KWin crashes, e.g. via kwriteconfig6 --file kwinrc --group Plugins --key kwin-scripting-event-loggerEnabled false; qdbus org.kde.KWin /KWin reconfigure.


OBSERVED RESULT

KWin crashes.


EXPECTED RESULT

Nothing crashes – neither KWin nor the script. However, this is debatable (see above).


SOFTWARE/OS VERSIONS

Operating System: Arch Linux
KDE Plasma Version: 6.0.4
KDE Frameworks Version: 6.1.0
Qt Version: 6.7.0
Kernel Version: 6.8.9-arch1-1 (64-bit)
Graphics Platform: Wayland
Processors: 8 × Intel® Core™ i7-4790 CPU @ 3.60GHz
Memory: 23,4 GiB of RAM
Graphics Processor: VERDE
Manufacturer: ASUS
Product Name: All Series
Comment 1 Flupp 2024-05-05 16:53:09 UTC
Created attachment 169217 [details]
backtrace
Comment 2 Vlad Zahorodnii 2024-08-28 12:27:10 UTC
After the windowRemoved signal is emitted, you MUST NOT use the window anymore, the script must drop all its references for the window.

If a script holds a reference to a closed window, its lifetime won't be extended.