diff mbox series

[FFmpeg-devel,23/30] avcodec/motionpixels: Cleanup generically after init failure

Message ID 20200915074000.102622-23-andreas.rheinhardt@gmail.com
State Accepted
Commit 0f1db365c7ce7c7c0ef3ee484e780abf7daaba1f
Headers show
Series [FFmpeg-devel,01/30] avcodec/flashsvenc: Avoid allocation of buffer, fix memleak
Related show

Checks

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

Commit Message

Andreas Rheinhardt Sept. 15, 2020, 7:39 a.m. UTC
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
 libavcodec/motionpixels.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)

Comments

Paul B Mahol Sept. 15, 2020, 9:12 a.m. UTC | #1
On Tue, Sep 15, 2020 at 09:39:53AM +0200, Andreas Rheinhardt wrote:
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
> ---
>  libavcodec/motionpixels.c | 11 +++--------
>  1 file changed, 3 insertions(+), 8 deletions(-)
> 


looks ok.

> diff --git a/libavcodec/motionpixels.c b/libavcodec/motionpixels.c
> index 6cb444a703..b48200b017 100644
> --- a/libavcodec/motionpixels.c
> +++ b/libavcodec/motionpixels.c
> @@ -81,19 +81,13 @@ static av_cold int mp_decode_init(AVCodecContext *avctx)
>      mp->offset_bits_len = av_log2(avctx->width * avctx->height) + 1;
>      mp->vpt = av_mallocz_array(avctx->height, sizeof(YuvPixel));
>      mp->hpt = av_mallocz_array(h4 / 4, w4 / 4 * sizeof(YuvPixel));
> -    if (!mp->changes_map || !mp->vpt || !mp->hpt) {
> -        av_freep(&mp->changes_map);
> -        av_freep(&mp->vpt);
> -        av_freep(&mp->hpt);
> +    if (!mp->changes_map || !mp->vpt || !mp->hpt)
>          return AVERROR(ENOMEM);
> -    }
>      avctx->pix_fmt = AV_PIX_FMT_RGB555;
>  
>      mp->frame = av_frame_alloc();
> -    if (!mp->frame) {
> -        mp_decode_end(avctx);
> +    if (!mp->frame)
>          return AVERROR(ENOMEM);
> -    }
>  
>      return 0;
>  }
> @@ -354,4 +348,5 @@ AVCodec ff_motionpixels_decoder = {
>      .close          = mp_decode_end,
>      .decode         = mp_decode_frame,
>      .capabilities   = AV_CODEC_CAP_DR1,
> +    .caps_internal  = FF_CODEC_CAP_INIT_CLEANUP,
>  };
> -- 
> 2.25.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/motionpixels.c b/libavcodec/motionpixels.c
index 6cb444a703..b48200b017 100644
--- a/libavcodec/motionpixels.c
+++ b/libavcodec/motionpixels.c
@@ -81,19 +81,13 @@  static av_cold int mp_decode_init(AVCodecContext *avctx)
     mp->offset_bits_len = av_log2(avctx->width * avctx->height) + 1;
     mp->vpt = av_mallocz_array(avctx->height, sizeof(YuvPixel));
     mp->hpt = av_mallocz_array(h4 / 4, w4 / 4 * sizeof(YuvPixel));
-    if (!mp->changes_map || !mp->vpt || !mp->hpt) {
-        av_freep(&mp->changes_map);
-        av_freep(&mp->vpt);
-        av_freep(&mp->hpt);
+    if (!mp->changes_map || !mp->vpt || !mp->hpt)
         return AVERROR(ENOMEM);
-    }
     avctx->pix_fmt = AV_PIX_FMT_RGB555;
 
     mp->frame = av_frame_alloc();
-    if (!mp->frame) {
-        mp_decode_end(avctx);
+    if (!mp->frame)
         return AVERROR(ENOMEM);
-    }
 
     return 0;
 }
@@ -354,4 +348,5 @@  AVCodec ff_motionpixels_decoder = {
     .close          = mp_decode_end,
     .decode         = mp_decode_frame,
     .capabilities   = AV_CODEC_CAP_DR1,
+    .caps_internal  = FF_CODEC_CAP_INIT_CLEANUP,
 };