X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavcodec%2Fzmbv.c;h=b01ce1bcf6e8ecef1acd61a132445b4600c9d0aa;hb=237bbf6678a0c3fc6962716edf72db1063de860c;hp=f91d2e393179d4a025ba1fef28ed5c73955aff35;hpb=7386b4ff39506b7a34b3689cc4b05993ed9b4a4f;p=ffmpeg diff --git a/libavcodec/zmbv.c b/libavcodec/zmbv.c index f91d2e39317..b01ce1bcf6e 100644 --- a/libavcodec/zmbv.c +++ b/libavcodec/zmbv.c @@ -57,6 +57,7 @@ typedef struct ZmbvContext { AVCodecContext *avctx; int bpp; + int alloc_bpp; unsigned int decomp_size; uint8_t* decomp_buf; uint8_t pal[768]; @@ -494,12 +495,17 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPac return AVERROR_UNKNOWN; } - c->cur = av_realloc_f(c->cur, avctx->width * avctx->height, (c->bpp / 8)); - c->prev = av_realloc_f(c->prev, avctx->width * avctx->height, (c->bpp / 8)); + if (c->alloc_bpp < c->bpp) { + c->cur = av_realloc_f(c->cur, avctx->width * avctx->height, (c->bpp / 8)); + c->prev = av_realloc_f(c->prev, avctx->width * avctx->height, (c->bpp / 8)); + c->alloc_bpp = c->bpp; + } c->bx = (c->width + c->bw - 1) / c->bw; c->by = (c->height+ c->bh - 1) / c->bh; - if (!c->cur || !c->prev) + if (!c->cur || !c->prev) { + c->alloc_bpp = 0; return AVERROR(ENOMEM); + } memset(c->cur, 0, avctx->width * avctx->height * (c->bpp / 8)); memset(c->prev, 0, avctx->width * avctx->height * (c->bpp / 8)); c->decode_intra= decode_intra; @@ -599,12 +605,11 @@ static av_cold int decode_init(AVCodecContext *avctx) c->decomp_size = (avctx->width + 255) * 4 * (avctx->height + 64); /* Allocate decompression buffer */ - if (c->decomp_size) { - if (!(c->decomp_buf = av_mallocz(c->decomp_size))) { - av_log(avctx, AV_LOG_ERROR, - "Can't allocate decompression buffer.\n"); - return AVERROR(ENOMEM); - } + c->decomp_buf = av_mallocz(c->decomp_size); + if (!c->decomp_buf) { + av_log(avctx, AV_LOG_ERROR, + "Can't allocate decompression buffer.\n"); + return AVERROR(ENOMEM); } c->zstream.zalloc = Z_NULL;