imgconvert: check memory allocations and propagate errors
authorVittorio Giovara <vittorio.giovara@gmail.com>
Wed, 17 Dec 2014 15:01:45 +0000 (16:01 +0100)
committerVittorio Giovara <vittorio.giovara@gmail.com>
Thu, 18 Dec 2014 22:27:14 +0000 (23:27 +0100)
libavcodec/imgconvert.c

index 365dc54..2d32602 100644 (file)
@@ -427,13 +427,15 @@ static void deinterlace_bottom_field(uint8_t *dst, int dst_wrap,
     deinterlace_line(dst,src_m2,src_m1,src_0,src_0,src_0,width);
 }
 
-static void deinterlace_bottom_field_inplace(uint8_t *src1, int src_wrap,
-                                             int width, int height)
+static int deinterlace_bottom_field_inplace(uint8_t *src1, int src_wrap,
+                                            int width, int height)
 {
     uint8_t *src_m1, *src_0, *src_p1, *src_p2;
     int y;
     uint8_t *buf;
     buf = av_malloc(width);
+    if (!buf)
+        return AVERROR(ENOMEM);
 
     src_m1 = src1;
     memcpy(buf,src_m1,width);
@@ -450,12 +452,13 @@ static void deinterlace_bottom_field_inplace(uint8_t *src1, int src_wrap,
     /* do last line */
     deinterlace_line_inplace(buf,src_m1,src_0,src_0,src_0,width);
     av_free(buf);
+    return 0;
 }
 
 int avpicture_deinterlace(AVPicture *dst, const AVPicture *src,
                           enum AVPixelFormat pix_fmt, int width, int height)
 {
-    int i;
+    int i, ret;
 
     if (pix_fmt != AV_PIX_FMT_YUV420P &&
         pix_fmt != AV_PIX_FMT_YUVJ420P &&
@@ -491,8 +494,11 @@ int avpicture_deinterlace(AVPicture *dst, const AVPicture *src,
             }
         }
         if (src == dst) {
-            deinterlace_bottom_field_inplace(dst->data[i], dst->linesize[i],
-                                 width, height);
+            ret = deinterlace_bottom_field_inplace(dst->data[i],
+                                                   dst->linesize[i],
+                                                   width, height);
+            if (ret < 0)
+                return ret;
         } else {
             deinterlace_bottom_field(dst->data[i],dst->linesize[i],
                                         src->data[i], src->linesize[i],