From 0b9565e859b861028cdaa4bd062bd724c02021bb Mon Sep 17 00:00:00 2001 From: Leandro Ribeiro Date: Tue, 4 Jun 2024 16:23:27 -0300 Subject: [PATCH] color-lcms: avoid destroying cprof without rofile In cmlcms_get_color_profile_from_icc(), if we fail to create the ro_anonymous_file we end up calling cmlcms_color_profile_destroy() with a cprof whose cprof->prof_rofile is NULL. For now that's alright, because cmlcms_color_profile_destroy() checks if this field is NULL. But in the future we'll drop this check, so the idea of this patch is to avoid an issue in the future. Reorganize cmlcms_get_color_profile_from_icc() to avoid destroying a cprof without a ro_anonymous_file. Signed-off-by: Leandro Ribeiro --- libweston/color-lcms/color-profile.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/libweston/color-lcms/color-profile.c b/libweston/color-lcms/color-profile.c index b50ad5d1..4bd84abb 100644 --- a/libweston/color-lcms/color-profile.c +++ b/libweston/color-lcms/color-profile.c @@ -575,6 +575,7 @@ cmlcms_get_color_profile_from_icc(struct weston_color_manager *cm_base, struct weston_color_manager_lcms *cm = to_cmlcms(cm_base); struct lcmsProfilePtr profile; struct cmlcms_md5_sum md5sum; + struct ro_anonymous_file *prof_rofile = NULL; struct cmlcms_color_profile *cprof = NULL; char *desc = NULL; @@ -613,20 +614,23 @@ cmlcms_get_color_profile_from_icc(struct weston_color_manager *cm_base, if (!desc) goto err_close; + prof_rofile = os_ro_anonymous_file_create(icc_len, icc_data); + if (!prof_rofile) + goto err_close; + cprof = cmlcms_color_profile_create(cm, profile, desc, errmsg); if (!cprof) goto err_close; cprof->type = CMLCMS_PROFILE_TYPE_ICC; - - cprof->prof_rofile = os_ro_anonymous_file_create(icc_len, icc_data); - if (!cprof->prof_rofile) - goto err_close; + cprof->prof_rofile = prof_rofile; *cprof_out = &cprof->base; return true; err_close: + if (prof_rofile) + os_ro_anonymous_file_destroy(prof_rofile); if (cprof) cmlcms_color_profile_destroy(cprof); free(desc);