From 61b3ae335a51d34343f73b76bbcf1bc64af0508e Mon Sep 17 00:00:00 2001 From: Pekka Paalanen Date: Fri, 23 Feb 2024 16:06:48 +0200 Subject: [PATCH] color-lcms: clean up context in init failure This is not strictly necessary, because if init fails, then weston_compositor_backends_loaded() fails, main.c will weston_compositor_destroy() -> weston_compositor_shutdown() -> cmclcms_destroy() which will free this. But that is very hard to track down, so let's make the code obviously more correct. We must also avoid cmsDeleteContext(NULL), because it will then do something to the default cms context rather than bail out. Signed-off-by: Pekka Paalanen --- libweston/color-lcms/color-lcms.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libweston/color-lcms/color-lcms.c b/libweston/color-lcms/color-lcms.c index 40ebe132..aa414592 100644 --- a/libweston/color-lcms/color-lcms.c +++ b/libweston/color-lcms/color-lcms.c @@ -437,6 +437,10 @@ cmlcms_init(struct weston_color_manager *cm_base) return true; out_err: + if (cm->lcms_ctx) + cmsDeleteContext(cm->lcms_ctx); + cm->lcms_ctx = NULL; + weston_log_scope_destroy(cm->transforms_scope); cm->transforms_scope = NULL; weston_log_scope_destroy(cm->optimizer_scope); @@ -480,7 +484,8 @@ cmlcms_destroy(struct weston_color_manager *cm_base) assert(wl_list_empty(&cm->color_transform_list)); assert(wl_list_empty(&cm->color_profile_list)); - cmsDeleteContext(cm->lcms_ctx); + if (cm->lcms_ctx) + cmsDeleteContext(cm->lcms_ctx); weston_log_scope_destroy(cm->transforms_scope); weston_log_scope_destroy(cm->optimizer_scope);