Skip to content

Commit

Permalink
heifsave: ensure NCLX profile is freed in lossless mode
Browse files Browse the repository at this point in the history
  • Loading branch information
kleisauke committed Aug 24, 2024
1 parent 1a86d4e commit aee3be3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
8.15.4

- heifsave: ensure NCLX profile is freed in lossless mode [kleisauke]

11/8/24 8.15.3

- fix dzsave of >8-bit images to JPEG
Expand Down
11 changes: 9 additions & 2 deletions libvips/foreign/heifsave.c
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,9 @@ vips_foreign_save_heif_write_page(VipsForeignSaveHeif *heif, int page)

struct heif_error error;
struct heif_encoding_options *options;
#ifdef HAVE_HEIF_ENCODING_OPTIONS_OUTPUT_NCLX_PROFILE
struct heif_color_profile_nclx *nclx;
#endif

#ifdef HAVE_HEIF_COLOR_PROFILE
/* A profile supplied as an argument overrides an embedded
Expand All @@ -293,9 +296,10 @@ vips_foreign_save_heif_write_page(VipsForeignSaveHeif *heif, int page)
/* Matrix coefficients have to be identity (CICP x/y/0) in lossless mode.
*/
if (heif->lossless) {
struct heif_color_profile_nclx *nclx = heif_nclx_color_profile_alloc();
if (!nclx)
if (!(nclx = heif_nclx_color_profile_alloc())) {
heif_encoding_options_free(options);
return -1;
}

nclx->matrix_coefficients = heif_matrix_coefficients_RGB_GBR;
options->output_nclx_profile = nclx;
Expand Down Expand Up @@ -324,6 +328,9 @@ vips_foreign_save_heif_write_page(VipsForeignSaveHeif *heif, int page)
#endif /*DEBUG*/

heif_encoding_options_free(options);
#ifdef HAVE_HEIF_ENCODING_OPTIONS_OUTPUT_NCLX_PROFILE
VIPS_FREEF(heif_nclx_color_profile_free, nclx);
#endif

if (error.code) {
vips__heif_error(&error);
Expand Down

0 comments on commit aee3be3

Please sign in to comment.