libweston: Improve weston_layer_fini() error handling

Cleanup view list when it's not empty to avoid referencing
about-to-free layer in the view's layer_link.

Signed-off-by: Jeffy Chen <jeffy.chen@rock-chips.com>
This commit is contained in:
Jeffy Chen 2024-02-20 10:55:20 +08:00
parent 661a7142ca
commit 2af55bac1e

View File

@ -4163,10 +4163,19 @@ weston_layer_fini(struct weston_layer *layer)
{
wl_list_remove(&layer->link);
if (!wl_list_empty(&layer->view_list.link))
if (!wl_list_empty(&layer->view_list.link)) {
struct weston_view *view, *tmp;
weston_log("BUG: finalizing a layer with views still on it.\n");
wl_list_remove(&layer->view_list.link);
wl_list_for_each_safe(view, tmp, &layer->view_list.link,
layer_link.link) {
wl_list_remove(&view->layer_link.link);
wl_list_init(&view->layer_link.link);
view->layer_link.layer = NULL;
}
}
}
/** Sets the position of the layer in the layer list. The layer will be placed