Fix race in wp_drm_lease_v1.

Basically this is a well known issue in wayland for globals. If bind
comes after destroyed, it will raise a invalid global error. The common
practice is to delay the destroy of global. Similar technique is also
applied to wl_output.

CCBUG: 452435
This commit is contained in:
Weng Xuetian 2022-04-16 00:01:12 -07:00
parent c157e948e2
commit 14ae6e3100
2 changed files with 6 additions and 10 deletions

View file

@ -84,10 +84,6 @@ void DrmLeaseDeviceV1InterfacePrivate::remove()
request->connectors.clear();
}
globalRemove();
removed = true;
if (resourceMap().isEmpty()) {
delete this;
}
}
void DrmLeaseDeviceV1InterfacePrivate::registerConnector(DrmLeaseConnectorV1Interface *connector)
@ -144,6 +140,9 @@ void DrmLeaseDeviceV1InterfacePrivate::wp_drm_lease_device_v1_release(Resource *
void DrmLeaseDeviceV1InterfacePrivate::wp_drm_lease_device_v1_bind_resource(Resource *resource)
{
if (isGlobalRemoved()) {
return;
}
if (!hasDrmMaster) {
pendingFds << resource->handle;
return;
@ -161,12 +160,9 @@ void DrmLeaseDeviceV1InterfacePrivate::wp_drm_lease_device_v1_bind_resource(Reso
}
}
void DrmLeaseDeviceV1InterfacePrivate::wp_drm_lease_device_v1_destroy_resource(Resource *resource)
void DrmLeaseDeviceV1InterfacePrivate::wp_drm_lease_device_v1_destroy_global()
{
Q_UNUSED(resource)
if (removed && resourceMap().isEmpty()) {
delete this;
}
delete this;
}

View file

@ -44,7 +44,7 @@ protected:
void wp_drm_lease_device_v1_create_lease_request(Resource *resource, uint32_t id) override;
void wp_drm_lease_device_v1_release(Resource *resource) override;
void wp_drm_lease_device_v1_bind_resource(Resource *resource) override;
void wp_drm_lease_device_v1_destroy_resource(Resource *resource) override;
void wp_drm_lease_device_v1_destroy_global() override;
};
class DrmLeaseConnectorV1InterfacePrivate : public QObject, public QtWaylandServer::wp_drm_lease_connector_v1