diff --git a/libheif/api/libheif/heif.cc b/libheif/api/libheif/heif.cc index 3b7ce8532f..bd83e851d3 100644 --- a/libheif/api/libheif/heif.cc +++ b/libheif/api/libheif/heif.cc @@ -1821,11 +1821,8 @@ struct heif_error heif_image_add_channel(struct heif_image* image, int width, int height, heif_channel_datatype datatype, int bit_depth) { - if (!image->image->add_channel(channel, width, height, datatype, bit_depth, nullptr)) { - struct heif_error err = {heif_error_Memory_allocation_error, - heif_suberror_Unspecified, - "Cannot allocate memory for image plane"}; - return err; + if (auto err = image->image->add_channel(channel, width, height, datatype, bit_depth, nullptr)) { + return err.error_struct(image->image.get()); } else { return heif_error_success;