diff mbox series

[FFmpeg-devel,23/23] avcodec/pngdec: Fix memleak by postponing allocation

Message ID 20210310215446.1396386-14-andreas.rheinhardt@gmail.com
State Accepted
Commit 5edcdfc318b62b8327565183e8f56b3f8dd2dd16
Headers show
Series [FFmpeg-devel,1/8] avcodec/cbs: Remove redundant checks for CodedBitstreamContext.codec | expand

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished

Commit Message

Andreas Rheinhardt March 10, 2021, 9:54 p.m. UTC
Fixes Coverity ticket #1322342.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
It seems to me that this temporary buffer is actually unneeded: One just
needs to use the new frame as destination for blending and then
overwrite the new frame's data outside the processed rectangle with the
data from the old frame. Or am I wrong about this?

 libavcodec/pngdec.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/pngdec.c b/libavcodec/pngdec.c
index a5a71ef161..63c22063d9 100644
--- a/libavcodec/pngdec.c
+++ b/libavcodec/pngdec.c
@@ -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) {