Fix memory leak when JpegEncode returns an error.

This commit is contained in:
Eric Soroos 2025-05-13 23:31:09 +02:00
parent f792e0b1ef
commit 789631c60c

View File

@ -131,6 +131,7 @@ ImagingJpegEncode(Imaging im, ImagingCodecState state, UINT8 *buf, int bytes) {
break; break;
default: default:
state->errcode = IMAGING_CODEC_CONFIG; state->errcode = IMAGING_CODEC_CONFIG;
jpeg_destroy_compress(&context->cinfo);
return -1; return -1;
} }
@ -161,6 +162,7 @@ ImagingJpegEncode(Imaging im, ImagingCodecState state, UINT8 *buf, int bytes) {
/* Would subsample the green and blue /* Would subsample the green and blue
channels, which doesn't make sense */ channels, which doesn't make sense */
state->errcode = IMAGING_CODEC_CONFIG; state->errcode = IMAGING_CODEC_CONFIG;
jpeg_destroy_compress(&context->cinfo);
return -1; return -1;
} }
jpeg_set_colorspace(&context->cinfo, JCS_RGB); jpeg_set_colorspace(&context->cinfo, JCS_RGB);