diff options
author | Paul B Mahol <onemda@gmail.com> | 2012-03-16 17:23:57 +0400 |
---|---|---|
committer | Ronald S. Bultje <rsbultje@gmail.com> | 2012-03-17 03:57:12 +0400 |
commit | 341404f753fdbcddebb9fbce51f2ef057cceb79c (patch) | |
tree | ea522957ea9d89482c0cdc56d178f63f7b911776 /libavcodec/vqavideo.c | |
parent | d3958ab4edf49cb760412d8687c870d349f692c7 (diff) |
vqavideo: check malloc return values
Signed-off-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Ronald S. Bultje <rsbultje@gmail.com>
Diffstat (limited to 'libavcodec/vqavideo.c')
-rw-r--r-- | libavcodec/vqavideo.c | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/libavcodec/vqavideo.c b/libavcodec/vqavideo.c index 7a6308aeb1..0a06a9f4e8 100644 --- a/libavcodec/vqavideo.c +++ b/libavcodec/vqavideo.c @@ -158,7 +158,18 @@ static av_cold int vqa_decode_init(AVCodecContext *avctx) /* allocate codebooks */ s->codebook_size = MAX_CODEBOOK_SIZE; s->codebook = av_malloc(s->codebook_size); + if (!s->codebook) + goto fail; s->next_codebook_buffer = av_malloc(s->codebook_size); + if (!s->next_codebook_buffer) + goto fail; + + /* allocate decode buffer */ + s->decode_buffer_size = (s->width / s->vector_width) * + (s->height / s->vector_height) * 2; + s->decode_buffer = av_malloc(s->decode_buffer_size); + if (!s->decode_buffer) + goto fail; /* initialize the solid-color vectors */ if (s->vector_height == 4) { @@ -174,14 +185,14 @@ static av_cold int vqa_decode_init(AVCodecContext *avctx) } s->next_codebook_buffer_index = 0; - /* allocate decode buffer */ - s->decode_buffer_size = (s->width / s->vector_width) * - (s->height / s->vector_height) * 2; - s->decode_buffer = av_malloc(s->decode_buffer_size); - s->frame.data[0] = NULL; return 0; +fail: + av_freep(&s->codebook); + av_freep(&s->next_codebook_buffer); + av_freep(&s->decode_buffer); + return AVERROR(ENOMEM); } #define CHECK_COUNT() \ @@ -589,9 +600,9 @@ static av_cold int vqa_decode_end(AVCodecContext *avctx) { VqaContext *s = avctx->priv_data; - av_free(s->codebook); - av_free(s->next_codebook_buffer); - av_free(s->decode_buffer); + av_freep(&s->codebook); + av_freep(&s->next_codebook_buffer); + av_freep(&s->decode_buffer); if (s->frame.data[0]) avctx->release_buffer(avctx, &s->frame); |