From 3866ecc5d34a50005097dec5eb8702b80c9af32b Mon Sep 17 00:00:00 2001 From: Michael Olbrich Date: Mon, 2 Dec 2024 11:32:46 +0100 Subject: [PATCH] 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 --- libweston/compositor.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/libweston/compositor.c b/libweston/compositor.c index afa757715..a54fe6f49 100644 --- a/libweston/compositor.c +++ b/libweston/compositor.c @@ -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);