[FFmpeg-cvslog] snowenc: check for memory allocation failures

Michael Niedermayer git at videolan.org
Wed Aug 28 16:59:15 CEST 2013


ffmpeg | branch: master | Michael Niedermayer <michaelni at gmx.at> | Wed Aug 28 16:52:30 2013 +0200| [129f50692ef3a1e38c4f349a08354a6b73b43024] | committer: Michael Niedermayer

snowenc: check for memory allocation failures

Signed-off-by: Michael Niedermayer <michaelni at gmx.at>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=129f50692ef3a1e38c4f349a08354a6b73b43024
---

 libavcodec/snowenc.c |    8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/libavcodec/snowenc.c b/libavcodec/snowenc.c
index ff96f89..33d7685 100644
--- a/libavcodec/snowenc.c
+++ b/libavcodec/snowenc.c
@@ -203,6 +203,9 @@ static av_cold int encode_init(AVCodecContext *avctx)
     s->m.me.map       = av_mallocz(ME_MAP_SIZE*sizeof(uint32_t));
     s->m.me.score_map = av_mallocz(ME_MAP_SIZE*sizeof(uint32_t));
     s->m.obmc_scratchpad= av_mallocz(MB_SIZE*MB_SIZE*12*sizeof(uint32_t));
+    if (!s->m.me.scratchpad || !s->m.me.map || !s->m.me.score_map || !s->m.obmc_scratchpad)
+        return AVERROR(ENOMEM);
+
     ff_h263_encode_init(&s->m); //mv_penalty
 
     s->max_ref_frames = FFMAX(FFMIN(avctx->refs, MAX_REF_FRAMES), 1);
@@ -210,6 +213,9 @@ static av_cold int encode_init(AVCodecContext *avctx)
     if(avctx->flags&CODEC_FLAG_PASS1){
         if(!avctx->stats_out)
             avctx->stats_out = av_mallocz(256);
+
+        if (!avctx->stats_out)
+            return AVERROR(ENOMEM);
     }
     if((avctx->flags&CODEC_FLAG_PASS2) || !(avctx->flags&CODEC_FLAG_QSCALE)){
         if(ff_rate_control_init(&s->m) < 0)
@@ -248,6 +254,8 @@ static av_cold int encode_init(AVCodecContext *avctx)
         for(i=0; i<s->max_ref_frames; i++){
             s->ref_mvs[i]= av_mallocz(size*sizeof(int16_t[2]));
             s->ref_scores[i]= av_mallocz(size*sizeof(uint32_t));
+            if (!s->ref_mvs[i] || !s->ref_scores[i])
+                return AVERROR(ENOMEM);
         }
     }
 



More information about the ffmpeg-cvslog mailing list