Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix memory leaks in function JpegEncoder::Encode #1074

Merged
merged 1 commit into from
Dec 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions examples/encoder_jpeg.cc
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,9 @@ bool JpegEncoder::Encode(const struct heif_image_handle* handle,
uint32_t skip = (exifdata[0]<<24) | (exifdata[1]<<16) | (exifdata[2]<<8) | exifdata[3];
if (skip > (exifsize - 4)) {
fprintf(stderr, "Invalid EXIF data (offset too large)\n");
free(exifdata);
jpeg_destroy_compress(&cinfo);
fclose(fp);
return false;
}
skip += 4;
Expand All @@ -188,6 +191,9 @@ bool JpegEncoder::Encode(const struct heif_image_handle* handle,

if (size > std::numeric_limits<uint32_t>::max()) {
fprintf(stderr, "EXIF larger than 4GB is not supported");
free(exifdata);
jpeg_destroy_compress(&cinfo);
fclose(fp);
return false;
}

Expand Down Expand Up @@ -258,6 +264,8 @@ bool JpegEncoder::Encode(const struct heif_image_handle* handle,

if (heif_image_get_bits_per_pixel(image, heif_channel_Y) != 8) {
fprintf(stderr, "JPEG writer cannot handle image with >8 bpp.\n");
jpeg_destroy_compress(&cinfo);
fclose(fp);
return false;
}

Expand Down
Loading