diff mbox series

[FFmpeg-devel,1/6] avcodec/bink: Fix memleak upon init failure

Message ID 20200904172026.28217-1-andreas.rheinhardt@gmail.com
State Accepted
Commit 4f672889481e7b3dc03c04b02a86836e94104e63
Headers show
Series [FFmpeg-devel,1/6] avcodec/bink: Fix memleak upon init failure | expand

Checks

Context Check Description
andriy/default pending
andriy/make success Make finished
andriy/make_fate success Make fate finished

Commit Message

Andreas Rheinhardt Sept. 4, 2020, 5:20 p.m. UTC
The init function first allocates an AVFrame and then some buffers; if
one of the buffers couldn't be allocated, the AVFrame leaks. Solve this
by setting the FF_CODEC_CAP_INIT_CLEANUP flag.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
 libavcodec/bink.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

Comments

Paul B Mahol Sept. 4, 2020, 5:40 p.m. UTC | #1
On 9/4/20, Andreas Rheinhardt <andreas.rheinhardt@gmail.com> wrote:
> The init function first allocates an AVFrame and then some buffers; if
> one of the buffers couldn't be allocated, the AVFrame leaks. Solve this
> by setting the FF_CODEC_CAP_INIT_CLEANUP flag.
>
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
> ---
>  libavcodec/bink.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
>

LGTM

> diff --git a/libavcodec/bink.c b/libavcodec/bink.c
> index f251ab4017..c7ef333bd4 100644
> --- a/libavcodec/bink.c
> +++ b/libavcodec/bink.c
> @@ -1381,10 +1381,8 @@ static av_cold int decode_init(AVCodecContext *avctx)
>      ff_hpeldsp_init(&c->hdsp, avctx->flags);
>      ff_binkdsp_init(&c->binkdsp);
>
> -    if ((ret = init_bundles(c)) < 0) {
> -        free_bundles(c);
> +    if ((ret = init_bundles(c)) < 0)
>          return ret;
> -    }
>
>      if (c->version == 'b') {
>          if (!binkb_initialised) {
> @@ -1424,4 +1422,5 @@ AVCodec ff_bink_decoder = {
>      .decode         = decode_frame,
>      .flush          = flush,
>      .capabilities   = AV_CODEC_CAP_DR1,
> +    .caps_internal  = FF_CODEC_CAP_INIT_CLEANUP,
>  };
> --
> 2.20.1
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
Paul B Mahol Sept. 4, 2020, 6:29 p.m. UTC | #2
On 9/4/20, Andreas Rheinhardt <andreas.rheinhardt@gmail.com> wrote:
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
> ---
>  libavcodec/bink.c | 16 +++++++++-------
>  1 file changed, 9 insertions(+), 7 deletions(-)
>

LGTM

> diff --git a/libavcodec/bink.c b/libavcodec/bink.c
> index 9fdfa37395..ec164d0165 100644
> --- a/libavcodec/bink.c
> +++ b/libavcodec/bink.c
> @@ -114,7 +114,7 @@ typedef struct Bundle {
>  typedef struct BinkContext {
>      AVCodecContext *avctx;
>      BlockDSPContext bdsp;
> -    HpelDSPContext hdsp;
> +    op_pixels_func put_pixels_tab;
>      BinkDSPContext binkdsp;
>      AVFrame        *last;
>      int            version;              ///< internal Bink file version
> @@ -927,7 +927,7 @@ static int binkb_decode_plane(BinkContext *c, AVFrame
> *frame, GetBitContext *gb,
>                  if (ref < ref_start || ref + 8*stride > ref_end) {
>                      av_log(c->avctx, AV_LOG_WARNING, "Reference block is
> out of bounds\n");
>                  } else if (ref + 8*stride < dst || ref >= dst + 8*stride) {
> -                    c->hdsp.put_pixels_tab[1][0](dst, ref, stride, 8);
> +                    c->put_pixels_tab(dst, ref, stride, 8);
>                  } else {
>                      put_pixels8x8_overlapped(dst, ref, stride);
>                  }
> @@ -943,7 +943,7 @@ static int binkb_decode_plane(BinkContext *c, AVFrame
> *frame, GetBitContext *gb,
>                  if (ref < ref_start || ref + 8 * stride > ref_end) {
>                      av_log(c->avctx, AV_LOG_WARNING, "Reference block is
> out of bounds\n");
>                  } else if (ref + 8*stride < dst || ref >= dst + 8*stride) {
> -                    c->hdsp.put_pixels_tab[1][0](dst, ref, stride, 8);
> +                    c->put_pixels_tab(dst, ref, stride, 8);
>                  } else {
>                      put_pixels8x8_overlapped(dst, ref, stride);
>                  }
> @@ -975,7 +975,7 @@ static int binkb_decode_plane(BinkContext *c, AVFrame
> *frame, GetBitContext *gb,
>                  if (ref < ref_start || ref + 8 * stride > ref_end) {
>                      av_log(c->avctx, AV_LOG_WARNING, "Reference block is
> out of bounds\n");
>                  } else if (ref + 8*stride < dst || ref >= dst + 8*stride) {
> -                    c->hdsp.put_pixels_tab[1][0](dst, ref, stride, 8);
> +                    c->put_pixels_tab(dst, ref, stride, 8);
>                  } else {
>                      put_pixels8x8_overlapped(dst, ref, stride);
>                  }
> @@ -1010,7 +1010,7 @@ static int bink_put_pixels(BinkContext *c,
>                 xoff, yoff);
>          return AVERROR_INVALIDDATA;
>      }
> -    c->hdsp.put_pixels_tab[1][0](dst, ref, stride, 8);
> +    c->put_pixels_tab(dst, ref, stride, 8);
>
>      return 0;
>  }
> @@ -1093,7 +1093,7 @@ static int bink_decode_plane(BinkContext *c, AVFrame
> *frame, GetBitContext *gb,
>              }
>              switch (blk) {
>              case SKIP_BLOCK:
> -                c->hdsp.put_pixels_tab[1][0](dst, prev, stride, 8);
> +                c->put_pixels_tab(dst, prev, stride, 8);
>                  break;
>              case SCALED_BLOCK:
>                  blk = get_value(c, BINK_SRC_SUB_BLOCK_TYPES);
> @@ -1345,6 +1345,7 @@ static av_cold int decode_init(AVCodecContext *avctx)
>      BinkContext * const c = avctx->priv_data;
>      static VLC_TYPE table[16 * 128][2];
>      static int binkb_initialised = 0;
> +    HpelDSPContext hdsp;
>      int i, ret;
>      int flags;
>
> @@ -1379,7 +1380,8 @@ static av_cold int decode_init(AVCodecContext *avctx)
>      avctx->color_range = c->version == 'k' ? AVCOL_RANGE_JPEG :
> AVCOL_RANGE_MPEG;
>
>      ff_blockdsp_init(&c->bdsp, avctx);
> -    ff_hpeldsp_init(&c->hdsp, avctx->flags);
> +    ff_hpeldsp_init(&hdsp, avctx->flags);
> +    c->put_pixels_tab = hdsp.put_pixels_tab[1][0];
>      ff_binkdsp_init(&c->binkdsp);
>
>      if ((ret = init_bundles(c)) < 0)
> --
> 2.20.1
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
diff mbox series

Patch

diff --git a/libavcodec/bink.c b/libavcodec/bink.c
index f251ab4017..c7ef333bd4 100644
--- a/libavcodec/bink.c
+++ b/libavcodec/bink.c
@@ -1381,10 +1381,8 @@  static av_cold int decode_init(AVCodecContext *avctx)
     ff_hpeldsp_init(&c->hdsp, avctx->flags);
     ff_binkdsp_init(&c->binkdsp);
 
-    if ((ret = init_bundles(c)) < 0) {
-        free_bundles(c);
+    if ((ret = init_bundles(c)) < 0)
         return ret;
-    }
 
     if (c->version == 'b') {
         if (!binkb_initialised) {
@@ -1424,4 +1422,5 @@  AVCodec ff_bink_decoder = {
     .decode         = decode_frame,
     .flush          = flush,
     .capabilities   = AV_CODEC_CAP_DR1,
+    .caps_internal  = FF_CODEC_CAP_INIT_CLEANUP,
 };