[FFmpeg-cvslog] vqavideo: check malloc return values
Paul B Mahol
git at videolan.org
Sat Mar 17 23:52:40 CET 2012
ffmpeg | branch: master | Paul B Mahol <onemda at gmail.com> | Fri Mar 16 13:23:57 2012 +0000| [341404f753fdbcddebb9fbce51f2ef057cceb79c] | committer: Ronald S. Bultje
vqavideo: check malloc return values
Signed-off-by: Paul B Mahol <onemda at gmail.com>
Signed-off-by: Ronald S. Bultje <rsbultje at gmail.com>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=341404f753fdbcddebb9fbce51f2ef057cceb79c
---
libavcodec/vqavideo.c | 27 +++++++++++++++++++--------
1 files changed, 19 insertions(+), 8 deletions(-)
diff --git a/libavcodec/vqavideo.c b/libavcodec/vqavideo.c
index 7a6308a..0a06a9f 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);
More information about the ffmpeg-cvslog
mailing list