libwebp: do not destroy jpeg codec twice on error

WebPPictureImportRGB() can fail on memory allocation. In this case,
jpeg_destroy_decompress() was already called, so do not go to Error.
Free metadata as an error is returned.

Change-Id: I045b072090e9063d3ad10369ad18b0f08bdffe9f
(cherry picked from commit 6e8a4126f2)
This commit is contained in:
Yannis Guyon 2022-01-12 14:47:49 +01:00 committed by James Zern
parent 9195ea0538
commit 286e7fceaa

View File

@ -336,7 +336,11 @@ int ReadJPEG(const uint8_t* const data, size_t data_size,
pic->width = width;
pic->height = height;
ok = WebPPictureImportRGB(pic, rgb, (int)stride);
if (!ok) goto Error;
if (!ok) {
pic->width = 0; // WebPPictureImportRGB() barely touches 'pic' on failure.
pic->height = 0; // Just reset dimensions but keep any 'custom_ptr' etc.
MetadataFree(metadata); // In case the caller forgets to free it on error.
}
End:
free(rgb);