libweston: create/destroy color profile id generator in a safe point

Currently we create the color profile id generator in
weston_compositor_backends_loaded() and destroy it in
weston_compositor_shutdown().

If something goes wrong and Weston does not start properly, we end up
calling weston_compositor_shutdown() for a struct weston_compositor
whose color profile id generator is NULL, crashing.

This fixes that, creating/destroying the id generator in
weston_compositor_create()/destroy().

Signed-off-by: Leandro Ribeiro <leandro.ribeiro@collabora.com>
This commit is contained in:
Leandro Ribeiro 2024-02-22 14:35:42 -03:00 committed by Pekka Paalanen
parent 042d02f422
commit ffe08c4344

View File

@ -9246,6 +9246,8 @@ weston_compositor_create(struct wl_display *display,
weston_compositor_install_capture_protocol(ec);
ec->color_profile_id_generator = weston_idalloc_create(ec);
wl_list_init(&ec->view_list);
wl_list_init(&ec->plane_list);
wl_list_init(&ec->layer_list);
@ -9336,11 +9338,6 @@ weston_compositor_shutdown(struct weston_compositor *ec)
ec->color_manager = NULL;
}
/* Already destroyed color manager, now we can safely destroy the color
* profile id generator. */
weston_idalloc_destroy(ec->color_profile_id_generator);
ec->color_profile_id_generator = NULL;
if (ec->renderer)
ec->renderer->destroy(ec);
@ -9454,9 +9451,6 @@ weston_compositor_backends_loaded(struct weston_compositor *compositor)
if (!compositor->color_manager)
return -1;
/* Create id generator before initing the color manager. */
compositor->color_profile_id_generator = weston_idalloc_create(compositor);
if (!compositor->color_manager->init(compositor->color_manager))
return -1;
@ -9770,6 +9764,8 @@ weston_compositor_destroy(struct weston_compositor *compositor)
weston_log_scope_destroy(compositor->libseat_debug);
compositor->libseat_debug = NULL;
weston_idalloc_destroy(compositor->color_profile_id_generator);
if (compositor->default_dmabuf_feedback) {
weston_dmabuf_feedback_destroy(compositor->default_dmabuf_feedback);
weston_dmabuf_feedback_format_table_destroy(compositor->dmabuf_feedback_format_table);