From 6875e8a5097d2f43fe1d2b34a1c228e26ff5638a Mon Sep 17 00:00:00 2001 From: Piotr Bandurski Date: Sat, 14 Sep 2013 14:02:15 +0200 Subject: [PATCH] avcodec/mationpixels: free memory after malloc failures --- libavcodec/motionpixels.c | 28 ++++++++++++++++------------ 1 files changed, 16 insertions(+), 12 deletions(-) diff --git a/libavcodec/motionpixels.c b/libavcodec/motionpixels.c index 1a62d47..fad1d8c 100644 --- a/libavcodec/motionpixels.c +++ b/libavcodec/motionpixels.c @@ -50,6 +50,19 @@ typedef struct MotionPixelsContext { int bswapbuf_size; } MotionPixelsContext; +static av_cold int mp_decode_end(AVCodecContext *avctx) +{ + MotionPixelsContext *mp = avctx->priv_data; + + av_freep(&mp->changes_map); + av_freep(&mp->vpt); + av_freep(&mp->hpt); + av_freep(&mp->bswapbuf); + av_frame_unref(&mp->frame); + + return 0; +} + static av_cold int mp_decode_init(AVCodecContext *avctx) { MotionPixelsContext *mp = avctx->priv_data; @@ -68,8 +81,10 @@ static av_cold int mp_decode_init(AVCodecContext *avctx) mp->offset_bits_len = av_log2(avctx->width * avctx->height) + 1; mp->vpt = av_mallocz(avctx->height * sizeof(YuvPixel)); mp->hpt = av_mallocz(h4 * w4 / 16 * sizeof(YuvPixel)); - if (!mp->changes_map || !mp->vpt || !mp->hpt) + if (!mp->changes_map || !mp->vpt || !mp->hpt) { + mp_decode_end(avctx); return AVERROR(ENOMEM); + } avctx->pix_fmt = AV_PIX_FMT_RGB555; avcodec_get_frame_defaults(&mp->frame); return 0; @@ -319,18 +334,7 @@ end: return buf_size; } -static av_cold int mp_decode_end(AVCodecContext *avctx) -{ - MotionPixelsContext *mp = avctx->priv_data; - - av_freep(&mp->changes_map); - av_freep(&mp->vpt); - av_freep(&mp->hpt); - av_freep(&mp->bswapbuf); - av_frame_unref(&mp->frame); - return 0; -} AVCodec ff_motionpixels_decoder = { .name = "motionpixels", -- 1.7.9