diff mbox series

[FFmpeg-devel,4/4] avcodec/msrleenc: Check frame allocations/references

Message ID GV1P250MB0737A225DFBA4451366181528F3AA@GV1P250MB0737.EURP250.PROD.OUTLOOK.COM
State Accepted
Commit 3cb0bd06a8dc154449b0cdff1c57a10ee55f8b30
Headers show
Series [FFmpeg-devel,1/4] avcodec/msrleenc: Replace stray \r by \n | expand

Checks

Context Check Description
yinshiyou/configure_loongarch64 warning Failed to apply patch
andriy/configure_x86 warning Failed to apply patch

Commit Message

Andreas Rheinhardt July 16, 2023, 2:51 p.m. UTC
Also allocate the AVFrame during init and use av_frame_replace()
to replace it later.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/msrleenc.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/msrleenc.c b/libavcodec/msrleenc.c
index d5931f42fe..11f7d2a319 100644
--- a/libavcodec/msrleenc.c
+++ b/libavcodec/msrleenc.c
@@ -37,7 +37,13 @@  typedef struct MSRLEContext {
 
 static av_cold int msrle_encode_init(AVCodecContext *avctx)
 {
+    MSRLEContext *s = avctx->priv_data;
+
     avctx->bits_per_coded_sample = 8;
+    s->last_frame = av_frame_alloc();
+    if (!s->last_frame)
+        return AVERROR(ENOMEM);
+
     return 0;
 }
 
@@ -265,13 +271,7 @@  static int msrle_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
         s->curframe = 0;
     *got_packet = 1;
 
-    if (!s->last_frame)
-        s->last_frame = av_frame_alloc();
-    else
-        av_frame_unref(s->last_frame);
-
-    av_frame_ref(s->last_frame, pict);
-    return 0;
+    return av_frame_replace(s->last_frame, pict);
 }
 
 static int msrle_encode_close(AVCodecContext *avctx)