Skip to content

Commit 789631c

Browse files
committed
Fix memory leak when JpegEncode returns an error.
1 parent f792e0b commit 789631c

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

src/libImaging/JpegEncode.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ ImagingJpegEncode(Imaging im, ImagingCodecState state, UINT8 *buf, int bytes) {
131131
break;
132132
default:
133133
state->errcode = IMAGING_CODEC_CONFIG;
134+
jpeg_destroy_compress(&context->cinfo);
134135
return -1;
135136
}
136137

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

0 commit comments

Comments
 (0)