[FFmpeg-cvslog] avcodec/mpeg4_unpack_bframes: reduce code duplication

James Almer git at videolan.org
Tue Mar 20 22:40:09 EET 2018


ffmpeg | branch: master | James Almer <jamrial at gmail.com> | Sun Mar 18 23:25:32 2018 -0300| [bd60116794b4baaf9a6fedfc68cb1ac4a383bb2d] | committer: James Almer

avcodec/mpeg4_unpack_bframes: reduce code duplication

Also fixes one potential leak of side data in out if
the av_packet_from_data() call fails.

Reviewed-by: Michael Niedermayer <michael at niedermayer.cc>
Signed-off-by: James Almer <jamrial at gmail.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=bd60116794b4baaf9a6fedfc68cb1ac4a383bb2d
---

 libavcodec/mpeg4_unpack_bframes_bsf.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/libavcodec/mpeg4_unpack_bframes_bsf.c b/libavcodec/mpeg4_unpack_bframes_bsf.c
index e227f58ec6..ba970794c5 100644
--- a/libavcodec/mpeg4_unpack_bframes_bsf.c
+++ b/libavcodec/mpeg4_unpack_bframes_bsf.c
@@ -108,8 +108,8 @@ static int mpeg4_unpack_bframes_filter(AVBSFContext *ctx, AVPacket *out)
         s->b_frame_buf      = create_new_buffer(in->data + pos_vop2, s->b_frame_buf_size);
         if (!s->b_frame_buf) {
             s->b_frame_buf_size = 0;
-            av_packet_free(&in);
-            return AVERROR(ENOMEM);
+            ret = AVERROR(ENOMEM);
+            goto fail;
         }
     }
 
@@ -122,14 +122,12 @@ static int mpeg4_unpack_bframes_filter(AVBSFContext *ctx, AVPacket *out)
         /* use frame from BSFContext */
         ret = av_packet_copy_props(out, in);
         if (ret < 0) {
-            av_packet_free(&in);
-            return ret;
+            goto fail;
         }
 
         ret = av_packet_from_data(out, s->b_frame_buf, s->b_frame_buf_size);
         if (ret < 0) {
-            av_packet_free(&in);
-            return ret;
+            goto fail;
         }
         if (in->size <= MAX_NVOP_SIZE) {
             /* N-VOP */
@@ -142,9 +140,8 @@ static int mpeg4_unpack_bframes_filter(AVBSFContext *ctx, AVPacket *out)
             s->b_frame_buf      = create_new_buffer(in->data, in->size);
             if (!s->b_frame_buf) {
                 s->b_frame_buf_size = 0;
-                av_packet_unref(out);
-                av_packet_free(&in);
-                return AVERROR(ENOMEM);
+                ret = AVERROR(ENOMEM);
+                goto fail;
             }
         }
     } else if (nb_vop >= 2) {
@@ -161,9 +158,12 @@ static int mpeg4_unpack_bframes_filter(AVBSFContext *ctx, AVPacket *out)
         av_packet_move_ref(out, in);
     }
 
+fail:
+    if (ret < 0)
+        av_packet_unref(out);
     av_packet_free(&in);
 
-    return 0;
+    return ret;
 }
 
 static int mpeg4_unpack_bframes_init(AVBSFContext *ctx)



More information about the ffmpeg-cvslog mailing list