libweston: fix crash when a client queries a destroyed output

A client can call get_xdg_output() at any time. If the output was destroyed,
then all output resources are orphaned. This includes clearing the user data of
the resource.
This can happen, for example, when a monitor or HDMI switch quickly toggles the
HDMI hotplug pin.

So check if a head is associated with the resource. If not, just create the
resource and then return immediately.

Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
This commit is contained in:
Michael Olbrich 2024-12-02 11:32:46 +01:00 committed by Marius Vlad
parent 67253b30e8
commit 3866ecc5d3

View file

@ -8762,7 +8762,7 @@ xdg_output_manager_get_xdg_output(struct wl_client *client,
{
int version = wl_resource_get_version(manager);
struct weston_head *head = wl_resource_get_user_data(output_resource);
struct weston_output *output = head->output;
struct weston_output *output;
struct wl_resource *resource;
resource = wl_resource_create(client, &zxdg_output_v1_interface,
@ -8772,12 +8772,23 @@ xdg_output_manager_get_xdg_output(struct wl_client *client,
return;
}
if (!head) {
/* No destroy callback, because the resource is not added to the
* heads resource list
*/
wl_resource_set_implementation(resource, &xdg_output_interface,
NULL, NULL);
return;
}
wl_list_insert(&head->xdg_output_resource_list,
wl_resource_get_link(resource));
wl_resource_set_implementation(resource, &xdg_output_interface,
NULL, xdg_output_unlist);
output = head->output;
zxdg_output_v1_send_logical_position(resource,
output->pos.c.x,
output->pos.c.y);