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 <leandro.ribeiro@collabora.com>
This commit is contained in:
Leandro Ribeiro 2024-06-04 16:23:27 -03:00
parent 93d086f068
commit 0b9565e859
1 changed files with 8 additions and 4 deletions

View File

@ -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);