anim_util: fix leaks on error
in ReadAnimatedWebP() & ReadAnimatedGIF() when AllocateFrames() fails
due to OOM
Tested:
for i in `seq 1 278`; do
export MALLOC_FAIL_AT=$i
./examples/anim_diff webp1 webp2
./examples/anim_diff gif1 gif2
done
@@ -241,7 +241,7 @@ static int ReadAnimatedWebP(const char filename[],
image->bgcolor = anim_info.bgcolor;
// Allocate frames.
- if (!AllocateFrames(image, anim_info.frame_count)) return 0;
+ if (!AllocateFrames(image, anim_info.frame_count)) goto End;
// Decode frames.
while (WebPAnimDecoderHasMoreFrames(dec)) {
@@ -558,7 +558,10 @@ static int ReadAnimatedGIF(const char filename[], AnimatedImage* const image,
}
}
// Allocate frames.
- AllocateFrames(image, frame_count);
+ if (!AllocateFrames(image, frame_count)) {
+ DGifCloseFile(gif, NULL);
+ return 0;
+ }
canvas_width = image->canvas_width;
canvas_height = image->canvas_height;
