]> git.sesse.net Git - ffmpeg/commitdiff
avcodec/pngdec: Fix memleak by postponing allocation
authorAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
Wed, 10 Mar 2021 19:16:32 +0000 (20:16 +0100)
committerAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
Thu, 18 Mar 2021 23:10:24 +0000 (00:10 +0100)
Fixes Coverity ticket #1322342.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
libavcodec/pngdec.c

index a5a71ef161cf886b7f31baa5799c22dcc981c098..63c22063d9dcf761aac4223997197a0eeb4e63a4 100644 (file)
@@ -1080,10 +1080,6 @@ static int handle_p_frame_apng(AVCodecContext *avctx, PNGDecContext *s,
         return AVERROR_PATCHWELCOME;
     }
 
-    buffer = av_malloc_array(s->image_linesize, s->height);
-    if (!buffer)
-        return AVERROR(ENOMEM);
-
     ff_thread_await_progress(&s->last_picture, INT_MAX, 0);
 
     // need to reset a rectangle to background:
@@ -1099,7 +1095,9 @@ static int handle_p_frame_apng(AVCodecContext *avctx, PNGDecContext *s,
         }
     }
 
-    memcpy(buffer, s->last_picture.f->data[0], s->image_linesize * s->height);
+    buffer = av_memdup(s->last_picture.f->data[0], s->image_linesize * s->height);
+    if (!buffer)
+        return AVERROR(ENOMEM);
 
     // Perform blending
     if (s->blend_op == APNG_BLEND_OP_SOURCE) {