Skip to content

Commit

Permalink
fix memory leaks in function JpegEncoder::Encode
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoxiaoafeifei committed Dec 21, 2023
1 parent 59b5856 commit 877de6b
Showing 1 changed file with 8 additions and 0 deletions.
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

0 comments on commit 877de6b

Please sign in to comment.