kwin/autotests/libxrenderutils/blendpicture_test.cpp
Martin Gräßlin d49fba5d30 [libkwinxrenderutils] Clean up static blend picture before going down
Summary:
The method xRenderBlendPicture created a static XRenderPicture on
first usage. To cleanup a XRenderPicture an xcb_connection_t* is needed.
As it's static the cleanup happens on exit handler and at that time Qt
already destroyed the xcb_connection_t*. With a certain chance this will
crash.

To expose the problem a Q_ASSERT(qApp) is added in the destructor of
XRenderPicture. Using xrenderBlendPicture() will hit this assert on
application exit. This is demonstrated by the added auto test.

The actual fix to the problem is moving the static variable out of
the method and introduce a global cleanup method just like the init
method. This is now called from Workspace dtor, so before application
goes down.

CCBUG: 363251

Reviewers: #plasma

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D1731
2016-06-13 15:29:07 +02:00

59 lines
1.8 KiB
C++

/********************************************************************
KWin - the KDE window manager
This file is part of the KDE project.
Copyright (C) 2016 Martin Gräßlin <mgraesslin@kde.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
#include <QtTest/QtTest>
#include <QLoggingCategory>
#include <QX11Info>
#include "../../libkwineffects/kwinxrenderutils.h"
class BlendPictureTest : public QObject
{
Q_OBJECT
private Q_SLOTS:
void initTestCase();
void cleanupTestCase();
void testDontCrashOnTeardown();
};
void BlendPictureTest::initTestCase()
{
KWin::XRenderUtils::init(QX11Info::connection(), QX11Info::appRootWindow());
}
void BlendPictureTest::cleanupTestCase()
{
KWin::XRenderUtils::cleanup();
}
void BlendPictureTest::testDontCrashOnTeardown()
{
// this test uses xrenderBlendPicture - the only idea is to trigger the creation
// closing the application should not crash
// see BUG 363251
const auto picture = KWin::xRenderBlendPicture(0.5);
// and a second one
const auto picture2 = KWin::xRenderBlendPicture(0.6);
Q_UNUSED(picture)
Q_UNUSED(picture2)
}
QTEST_MAIN(BlendPictureTest)
#include "blendpicture_test.moc"