Cleanup Virtual Desktop Manager list entry in PlasmaVirtualDesktop destructor

Summary:
Current code contains a path to cleanup
PlasmaVirtualDesktopManagementInterface's list of destops if the
PlasmaVirtualDesktop object is destroyed.

However at the time that this is run, the entry in the list is already
dangling and therefore shouldn't be used.

This patch moves the cleanup logic into the destructor of
PlasmaVirtualDesktop, however this means we need to make sure
PlasmaVirtualDesktopManagementInterface outlives the
PlasmaVirtualDesktop by performing an explicit early cleanup instead of
relying on QObject.

Test Plan: Relevant unit test still passes.

Reviewers: #kwin, mart

Reviewed By: #kwin, mart

Subscribers: kde-frameworks-devel

Tags: #frameworks

Differential Revision: https://phabricator.kde.org/D16686
This commit is contained in:
David Edmundson 2018-11-13 16:16:19 +00:00
parent 800b0bece7
commit 1414e2abcc

View file

@ -180,7 +180,10 @@ PlasmaVirtualDesktopManagementInterface::PlasmaVirtualDesktopManagementInterface
}
PlasmaVirtualDesktopManagementInterface::~PlasmaVirtualDesktopManagementInterface()
{}
{
Q_D();
qDeleteAll(d->desktops);
}
PlasmaVirtualDesktopManagementInterface::Private *PlasmaVirtualDesktopManagementInterface::d_func() const
{
@ -219,20 +222,6 @@ PlasmaVirtualDesktopInterface *PlasmaVirtualDesktopManagementInterface::createDe
}
d->desktops.insert(actualPosition, desktop);
//NOTE: this in case the desktop has been deleted but not through removeDesktop
connect(desktop, &QObject::destroyed, this,
[this, id] {
Q_D();
auto i = d->findDesktop(id);
if (i != d->desktops.end()) {
for (auto it = d->resources.constBegin(); it != d->resources.constEnd(); ++it) {
org_kde_plasma_virtual_desktop_management_send_desktop_removed(*it, id.toUtf8().constData());
}
d->desktops.erase(i);
}
}
);
for (auto it = d->resources.constBegin(); it != d->resources.constEnd(); ++it) {
org_kde_plasma_virtual_desktop_management_send_desktop_created(*it, id.toUtf8().constData(), actualPosition);
@ -343,7 +332,9 @@ PlasmaVirtualDesktopInterface::PlasmaVirtualDesktopInterface(PlasmaVirtualDeskto
}
PlasmaVirtualDesktopInterface::~PlasmaVirtualDesktopInterface()
{}
{
d->vdm->removeDesktop(id());
}
QString PlasmaVirtualDesktopInterface::id() const
{