[FFmpeg-cvslog] snow: Check mallocs at init

Martin Storsjö git at videolan.org
Tue Oct 16 16:36:08 CEST 2012


ffmpeg | branch: release/0.10 | Martin Storsjö <martin at martin.st> | Mon Jul  2 10:39:25 2012 +0300| [31bc3fb563b12931cc4e2175adbeec92a5de05f1] | committer: Anton Khirnov

snow: Check mallocs at init

Signed-off-by: Martin Storsjö <martin at martin.st>
(cherry picked from commit 4d8516fdb15d0177ad745228508254dee187dff9)

Conflicts:

	libavcodec/snow.c

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

 libavcodec/snow.c    |   15 ++++++++++-----
 libavcodec/snowdec.c |    7 ++++++-
 libavcodec/snowenc.c |    7 +++++--
 3 files changed, 21 insertions(+), 8 deletions(-)

diff --git a/libavcodec/snow.c b/libavcodec/snow.c
index 905e02a..612f56a 100644
--- a/libavcodec/snow.c
+++ b/libavcodec/snow.c
@@ -385,7 +385,7 @@ mca( 8, 8,8)
 av_cold int ff_snow_common_init(AVCodecContext *avctx){
     SnowContext *s = avctx->priv_data;
     int width, height;
-    int i, j;
+    int i, j, ret;
 
     s->avctx= avctx;
     s->max_ref_frames=1; //just make sure its not an invalid value in case of no initial keyframe
@@ -438,17 +438,22 @@ av_cold int ff_snow_common_init(AVCodecContext *avctx){
     width= s->avctx->width;
     height= s->avctx->height;
 
-    s->spatial_idwt_buffer= av_mallocz(width*height*sizeof(IDWTELEM));
-    s->spatial_dwt_buffer= av_mallocz(width*height*sizeof(DWTELEM)); //FIXME this does not belong here
+    FF_ALLOCZ_OR_GOTO(avctx, s->spatial_idwt_buffer, width * height * sizeof(IDWTELEM), fail);
+    FF_ALLOCZ_OR_GOTO(avctx, s->spatial_dwt_buffer,  width * height * sizeof(DWTELEM),  fail); //FIXME this does not belong here
 
     for(i=0; i<MAX_REF_FRAMES; i++)
         for(j=0; j<MAX_REF_FRAMES; j++)
             scale_mv_ref[i][j] = 256*(i+1)/(j+1);
 
-    s->avctx->get_buffer(s->avctx, &s->mconly_picture);
-    s->scratchbuf = av_malloc(s->mconly_picture.linesize[0]*7*MB_SIZE);
+    if ((ret = s->avctx->get_buffer(s->avctx, &s->mconly_picture)) < 0) {
+        av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed\n");
+        return ret;
+    }
+    FF_ALLOC_OR_GOTO(avctx, s->scratchbuf, s->mconly_picture.linesize[0]*7*MB_SIZE, fail);
 
     return 0;
+fail:
+    return AVERROR(ENOMEM);
 }
 
 int ff_snow_common_init_after_header(AVCodecContext *avctx) {
diff --git a/libavcodec/snowdec.c b/libavcodec/snowdec.c
index 70c5d4a..049d4a6 100644
--- a/libavcodec/snowdec.c
+++ b/libavcodec/snowdec.c
@@ -354,9 +354,14 @@ static int decode_header(SnowContext *s){
 
 static av_cold int decode_init(AVCodecContext *avctx)
 {
+    int ret;
+
     avctx->pix_fmt= PIX_FMT_YUV420P;
 
-    ff_snow_common_init(avctx);
+    if ((ret = ff_snow_common_init(avctx)) < 0) {
+        ff_snow_common_end(avctx->priv_data);
+        return ret;
+    }
 
     return 0;
 }
diff --git a/libavcodec/snowenc.c b/libavcodec/snowenc.c
index 05b6f0f..d9fba96 100644
--- a/libavcodec/snowenc.c
+++ b/libavcodec/snowenc.c
@@ -156,7 +156,7 @@ static void dwt_quantize(SnowContext *s, Plane *p, DWTELEM *buffer, int width, i
 static av_cold int encode_init(AVCodecContext *avctx)
 {
     SnowContext *s = avctx->priv_data;
-    int plane_index;
+    int plane_index, ret;
 
     if(avctx->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL){
         av_log(avctx, AV_LOG_ERROR, "This codec is under development, files encoded with it may not be decodable with future versions!!!\n"
@@ -185,7 +185,10 @@ static av_cold int encode_init(AVCodecContext *avctx)
         s->plane[plane_index].fast_mc= 1;
     }
 
-    ff_snow_common_init(avctx);
+    if ((ret = ff_snow_common_init(avctx)) < 0) {
+        ff_snow_common_end(avctx->priv_data);
+        return ret;
+    }
     ff_snow_alloc_blocks(s);
 
     s->version=0;



More information about the ffmpeg-cvslog mailing list