From 618c330ca80d525f6666f76c17cc4568ba5675fe Mon Sep 17 00:00:00 2001 From: Aleix Pol Date: Sun, 28 Feb 2021 03:41:04 +0100 Subject: [PATCH] Do not attempt to compare iterators of potentially different containers I got this crash after leaving my system unattended: ``` 0 std::__atomic_base::load(std::memory_order) const (this=0x0, __m=std::memory_order_relaxed) at /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/10.2.0/../../../../include/c++/10.2.0/bits/atomic_base.h:426 1 QAtomicOps::loadRelaxed(std::atomic const&) (_q_value=...) at /home/apol/devel/kde5/include/QtCore/qatomic_cxx11.h:239 2 QBasicAtomicInteger::loadRelaxed() const (this=0x0) at /home/apol/devel/kde5/include/QtCore/qbasicatomic.h:107 3 QtPrivate::RefCount::isShared() const (this=0x0) at /home/apol/devel/kde5/include/QtCore/qrefcount.h:101 4 QMap::detach() (this=0x7f1b577b7870 ) at /home/apol/devel/kde5/include/QtCore/qmap.h:357 5 QMap::find(KWin::Group* const&) (this=0x7f1b577b7870 , akey=) at /home/apol/devel/kde5/include/QtCore/qmap.h:861 6 KWin::Workspace::constrainedStackingOrder() (this=this@entry=0x564b368c6290) at /home/apol/devel/frameworks/kwin/src/layers.cpp:502 7 0x00007f1b5708d027 in KWin::Workspace::updateStackingOrder(bool) (this=0x564b368c6290, propagate_new_clients=false) at /home/apol/devel/frameworks/kwin/src/layers.cpp:110 8 0x00007f1b571629be in KWin::X11Client::setFrameGeometry(QRect const&, KWin::AbstractClient::ForceGeometry_t) (this=0x564b374b4e60, rect=, force=) at /home/apol/devel/frameworks/kwin/src/x11client.cpp:4193 9 0x00007f1b57003fbf in KWin::AbstractClient::blockGeometryUpdates(bool) (this=this@entry=0x564b374b4e60, block=) at /home/apol/devel/frameworks/kwin/src/abstract_client.cpp:871 10 0x00007f1b570054f1 in KWin::GeometryUpdatesBlocker::~GeometryUpdatesBlocker() (this=) at /home/apol/devel/frameworks/kwin/src/abstract_client.h:1334 11 KWin::AbstractClient::checkWorkspacePosition(QRect, int, QRect) (this=0x564b374b4e60, oldGeometry=..., oldDesktop=1, oldClientGeometry=...) at /home/apol/devel/frameworks/kwin/src/abstract_client.cpp:3189 12 0x00007f1b571409e0 in KWin::Workspace::updateClientArea(bool) (this=, this@entry=0x564b368c6290, force=false) at /home/apol/devel/frameworks/kwin/src/workspace.cpp:2234 13 0x00007f1b57138fc6 in KWin::Workspace::updateClientArea() (this=0x564b368c6290) at /home/apol/devel/frameworks/kwin/src/workspace.cpp:2243 14 KWin::Workspace::desktopResized() (this=0x564b368c6290) at /home/apol/devel/frameworks/kwin/src/workspace.cpp:1980 15 0x00007f1b57707806 in QtPrivate::QSlotObjectBase::call(QObject*, void**) (a=0x7fff671a2e50, r=0x564b368c6290, this=0x564b372f1860) at ../../include/QtCore/../../../../../devel/frameworks/qt5/qtbase/src/corelib/kernel/qobjectdefs_impl.h:398 16 doActivate(QObject*, int, void**) (sender=0x564b368a0fe0, signal_index=4, argv=0x7fff671a2e50) at /home/apol/devel/frameworks/qt5/qtbase/src/corelib/kernel/qobject.cpp:3886 17 0x00007f1b57707806 in QtPrivate::QSlotObjectBase::call(QObject*, void**) (a=0x7fff671a2f30, r=0x564b368a0fe0, this=0x564b368a10f0) at ../../include/QtCore/../../../../../devel/frameworks/qt5/qtbase/src/corelib/kernel/qobjectdefs_impl.h:398 18 doActivate(QObject*, int, void**) (sender=0x564b36775640, signal_index=3, argv=0x7fff671a2f30) at /home/apol/devel/frameworks/qt5/qtbase/src/corelib/kernel/qobject.cpp:3886 19 0x00007f1b4ee2f9c3 in KWin::DrmBackend::updateOutputs() (this=this@entry=0x564b36775640) at /home/apol/devel/frameworks/kwin/src/plugins/platforms/drm/drm_backend.cpp:374 20 0x00007f1b4ee31d54 in KWin::DrmBackend::openDrm()::$_2::operator()() const (this=) at /home/apol/devel/frameworks/kwin/src/plugins/platforms/drm/drm_backend.cpp:328 ``` --- src/layers.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/layers.cpp b/src/layers.cpp index a82fed2b80..e5a23a3359 100644 --- a/src/layers.cpp +++ b/src/layers.cpp @@ -499,8 +499,9 @@ QList Workspace::constrainedStackingOrder() const int screen = (*it)->screen(); X11Client *c = qobject_cast(*it); - QMap< Group*, Layer >::iterator mLayer = minimum_layer[screen].find(c ? c->group() : nullptr); - if (mLayer != minimum_layer[screen].end()) { + QMultiMap ¤t = minimum_layer[screen]; + QMultiMap::iterator mLayer = current.find(c ? c->group() : nullptr); + if (mLayer != current.end()) { // If a window is raised above some other window in the same window group // which is in the ActiveLayer (i.e. it's fulscreened), make sure it stays // above that window (see #95731). @@ -508,7 +509,7 @@ QList Workspace::constrainedStackingOrder() l = ActiveLayer; *mLayer = l; } else if (c) { - minimum_layer[screen].insert(c->group(), l); + current.insert(c->group(), l); } layer[ l ].append(*it); }