From ec34fd70239e69326b5d8aa25fa33b761b0db66c Mon Sep 17 00:00:00 2001 From: James Zern Date: Mon, 4 Apr 2022 10:49:42 -0700 Subject: [PATCH] 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 Change-Id: I5d486c2c2982ae088e34a25d8e3e0188df1a9b51 --- examples/anim_util.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/examples/anim_util.c b/examples/anim_util.c index 97b32c07..cf7da4c0 100644 --- a/examples/anim_util.c +++ b/examples/anim_util.c @@ -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;