lavfi: check all avfilter_ref_buffer() calls for errors.
authorAnton Khirnov <anton@khirnov.net>
Sun, 15 Jul 2012 09:16:53 +0000 (11:16 +0200)
committerAnton Khirnov <anton@khirnov.net>
Sun, 22 Jul 2012 07:14:05 +0000 (09:14 +0200)
15 files changed:
libavfilter/fifo.c
libavfilter/split.c
libavfilter/vf_delogo.c
libavfilter/vf_frei0r.c
libavfilter/vf_gradfun.c
libavfilter/vf_overlay.c
libavfilter/vf_pixdesctest.c
libavfilter/vf_scale.c
libavfilter/vf_select.c
libavfilter/vf_transpose.c
libavfilter/vf_vflip.c
libavfilter/vf_yadif.c
libavfilter/video.c
libavfilter/vsrc_color.c
libavfilter/vsrc_movie.c

index 8264d5302ebeb5ccefe87a2e73c3b301cd394363..3226a0ddbeb88a996d7db40882ef974bb92a9516 100644 (file)
@@ -169,6 +169,9 @@ static int return_audio_frame(AVFilterContext *ctx)
             queue_pop(s);
         } else {
             buf_out = avfilter_ref_buffer(head, AV_PERM_READ);
+            if (!buf_out)
+                return AVERROR(ENOMEM);
+
             buf_out->audio->nb_samples = link->request_samples;
             buffer_offset(link, head, link->request_samples);
         }
index 469f69d76ac01163b27436a6203d391263b0ad53..084d555f1aa52f8265415e8e1e0c42b7e7dbff6c 100644 (file)
@@ -69,8 +69,11 @@ static int start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref)
     int i, ret = 0;
 
     for (i = 0; i < ctx->nb_outputs; i++) {
-        ret = ff_start_frame(ctx->outputs[i],
-                             avfilter_ref_buffer(picref, ~AV_PERM_WRITE));
+        AVFilterBufferRef *buf_out = avfilter_ref_buffer(picref, ~AV_PERM_WRITE);
+        if (!buf_out)
+            return AVERROR(ENOMEM);
+
+        ret = ff_start_frame(ctx->outputs[i], buf_out);
         if (ret < 0)
             break;
     }
@@ -126,8 +129,14 @@ static int filter_samples(AVFilterLink *inlink, AVFilterBufferRef *samplesref)
     int i, ret = 0;
 
     for (i = 0; i < ctx->nb_outputs; i++) {
-        ret = ff_filter_samples(inlink->dst->outputs[i],
-                                avfilter_ref_buffer(samplesref, ~AV_PERM_WRITE));
+        AVFilterBufferRef *buf_out = avfilter_ref_buffer(samplesref,
+                                                         ~AV_PERM_WRITE);
+        if (!buf_out) {
+            ret = AVERROR(ENOMEM);
+            break;
+        }
+
+        ret = ff_filter_samples(inlink->dst->outputs[i], buf_out);
         if (ret < 0)
             break;
     }
index 81f33b727ef15ccf6dcbf8958bccd2eb1bc1a8ad..343585fc5e0b2db653c3234084c8e05508d6f047 100644 (file)
@@ -217,7 +217,7 @@ static av_cold int init(AVFilterContext *ctx, const char *args)
 static int start_frame(AVFilterLink *inlink, AVFilterBufferRef *inpicref)
 {
     AVFilterLink *outlink = inlink->dst->outputs[0];
-    AVFilterBufferRef *outpicref = NULL;
+    AVFilterBufferRef *outpicref = NULL, *for_next_filter;
     int ret = 0;
 
     if (inpicref->perms & AV_PERM_PRESERVE) {
@@ -235,7 +235,12 @@ static int start_frame(AVFilterLink *inlink, AVFilterBufferRef *inpicref)
             return AVERROR(ENOMEM);
     }
 
-    ret = ff_start_frame(outlink, avfilter_ref_buffer(outpicref, ~0));
+    for_next_filter = avfilter_ref_buffer(outpicref, ~0);
+    if (for_next_filter)
+        ret = ff_start_frame(outlink, for_next_filter);
+    else
+        ret = AVERROR(ENOMEM);
+
     if (ret < 0) {
         avfilter_unref_bufferp(&outpicref);
         return ret;
index f5e9128d317bd10ead434b801e036989c2e320d8..152795f5b64feb81fb13fca5ebbd04de9d1f88fa 100644 (file)
@@ -438,13 +438,20 @@ static int source_request_frame(AVFilterLink *outlink)
 {
     Frei0rContext *frei0r = outlink->src->priv;
     AVFilterBufferRef *picref = ff_get_video_buffer(outlink, AV_PERM_WRITE, outlink->w, outlink->h);
+    AVFilterBufferRef *buf_out;
     int ret;
 
     picref->video->pixel_aspect = (AVRational) {1, 1};
     picref->pts = frei0r->pts++;
     picref->pos = -1;
 
-    ret = ff_start_frame(outlink, avfilter_ref_buffer(picref, ~0));
+    buf_out = avfilter_ref_buffer(picref, ~0);
+    if (!buf_out) {
+        ret = AVERROR(ENOMEM);
+        goto fail;
+    }
+
+    ret = ff_start_frame(outlink, buf_out);
     if (ret < 0)
         goto fail;
 
index d73e83386523b858b789e9b2b8f0514c6efefd71..52dcb7092fc9f1d3a23b6461adec492098757840 100644 (file)
@@ -183,7 +183,7 @@ static int config_input(AVFilterLink *inlink)
 static int start_frame(AVFilterLink *inlink, AVFilterBufferRef *inpicref)
 {
     AVFilterLink *outlink = inlink->dst->outputs[0];
-    AVFilterBufferRef *outpicref = NULL;
+    AVFilterBufferRef *outpicref = NULL, *for_next_filter;
     int ret = 0;
 
     if (inpicref->perms & AV_PERM_PRESERVE) {
@@ -200,7 +200,12 @@ static int start_frame(AVFilterLink *inlink, AVFilterBufferRef *inpicref)
             return AVERROR(ENOMEM);
     }
 
-    ret = ff_start_frame(outlink, avfilter_ref_buffer(outpicref, ~0));
+    for_next_filter = avfilter_ref_buffer(outpicref, ~0);
+    if (for_next_filter)
+        ret = ff_start_frame(outlink, for_next_filter);
+    else
+        ret = AVERROR(ENOMEM);
+
     if (ret < 0) {
         avfilter_unref_bufferp(&outpicref);
         return ret;
index 951ea7a4f64b385daab5f16165ec183dcd899503..14304c1918ea40ed44ff398529851c7ea11c4bc3 100644 (file)
@@ -213,6 +213,9 @@ static int start_frame(AVFilterLink *inlink, AVFilterBufferRef *inpicref)
     AVFilterContext *ctx = inlink->dst;
     OverlayContext *over = ctx->priv;
 
+    if (!outpicref)
+        return AVERROR(ENOMEM);
+
     outpicref->pts = av_rescale_q(outpicref->pts, ctx->inputs[MAIN]->time_base,
                                   ctx->outputs[0]->time_base);
 
index caf0852045f2e675b2ced62472f7676df54102ed..11905e625c1ee29f23e624620f8dbc94e636840e 100644 (file)
@@ -55,7 +55,7 @@ static int start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref)
 {
     PixdescTestContext *priv = inlink->dst->priv;
     AVFilterLink *outlink    = inlink->dst->outputs[0];
-    AVFilterBufferRef *outpicref;
+    AVFilterBufferRef *outpicref, *for_next_filter;
     int i, ret = 0;
 
     outpicref = ff_get_video_buffer(outlink, AV_PERM_WRITE,
@@ -80,7 +80,12 @@ static int start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref)
         priv->pix_desc->flags & PIX_FMT_PSEUDOPAL)
         memcpy(outpicref->data[1], outpicref->data[1], 256*4);
 
-    ret = ff_start_frame(outlink, avfilter_ref_buffer(outpicref, ~0));
+    for_next_filter = avfilter_ref_buffer(outpicref, ~0);
+    if (for_next_filter)
+        ret = ff_start_frame(outlink, for_next_filter);
+    else
+        ret = AVERROR(ENOMEM);
+
     if (ret < 0) {
         avfilter_unref_bufferp(&outpicref);
         return ret;
index 73f31a65fd864270e204828cbdd1f2a42849e993..66005303f529a03cc5f11a63a29055a5340651fe 100644 (file)
@@ -256,11 +256,14 @@ static int start_frame(AVFilterLink *link, AVFilterBufferRef *picref)
 {
     ScaleContext *scale = link->dst->priv;
     AVFilterLink *outlink = link->dst->outputs[0];
-    AVFilterBufferRef *outpicref;
+    AVFilterBufferRef *outpicref, *for_next_filter;
     int ret = 0;
 
     if (!scale->sws) {
-        return ff_start_frame(outlink, avfilter_ref_buffer(picref, ~0));
+        outpicref = avfilter_ref_buffer(picref, ~0);
+        if (!outpicref)
+            return AVERROR(ENOMEM);
+        return ff_start_frame(outlink, outpicref);
     }
 
     scale->hsub = av_pix_fmt_descriptors[link->format].log2_chroma_w;
@@ -281,7 +284,12 @@ static int start_frame(AVFilterLink *link, AVFilterBufferRef *picref)
               INT_MAX);
 
     scale->slice_y = 0;
-    ret = ff_start_frame(outlink, avfilter_ref_buffer(outpicref, ~0));
+    for_next_filter = avfilter_ref_buffer(outpicref, ~0);
+    if (for_next_filter)
+        ret = ff_start_frame(outlink, for_next_filter);
+    else
+        ret = AVERROR(ENOMEM);
+
     if (ret < 0) {
         avfilter_unref_bufferp(&outpicref);
         return ret;
index b4a424e1d2e7bb5fda61d4de6dd8eef23a8b3e7c..59030ebced65030455b3830879fe251fd332435c 100644 (file)
@@ -233,6 +233,7 @@ static int start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref)
 
     select->select = select_frame(inlink->dst, picref);
     if (select->select) {
+        AVFilterBufferRef *buf_out;
         /* frame was requested through poll_frame */
         if (select->cache_frames) {
             if (!av_fifo_space(select->pending_frames))
@@ -243,7 +244,10 @@ static int start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref)
                                       sizeof(picref), NULL);
             return 0;
         }
-        return ff_start_frame(inlink->dst->outputs[0], avfilter_ref_buffer(picref, ~0));
+        buf_out = avfilter_ref_buffer(picref, ~0);
+        if (!buf_out)
+            return AVERROR(ENOMEM);
+        return ff_start_frame(inlink->dst->outputs[0], buf_out);
     }
 
     return 0;
index 49b54d760b5d55ddc791f2069141e86f57ec495f..90f08e42cdeacf00b445f8007164478d45a7113d 100644 (file)
@@ -120,6 +120,7 @@ static int config_props_output(AVFilterLink *outlink)
 static int start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref)
 {
     AVFilterLink *outlink = inlink->dst->outputs[0];
+    AVFilterBufferRef *buf_out;
 
     outlink->out_buf = ff_get_video_buffer(outlink, AV_PERM_WRITE,
                                            outlink->w, outlink->h);
@@ -135,7 +136,10 @@ static int start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref)
         outlink->out_buf->video->pixel_aspect.den = picref->video->pixel_aspect.num;
     }
 
-    return ff_start_frame(outlink, avfilter_ref_buffer(outlink->out_buf, ~0));
+    buf_out = avfilter_ref_buffer(outlink->out_buf, ~0);
+    if (!buf_out)
+        return AVERROR(ENOMEM);
+    return ff_start_frame(outlink, buf_out);
 }
 
 static int end_frame(AVFilterLink *inlink)
index dc7604c52a027d57158a92d47ad49f06c7a0e036..b3143229b1e25e5dd04a2077a1c9e31ec1aaff9a 100644 (file)
@@ -70,6 +70,9 @@ static int start_frame(AVFilterLink *link, AVFilterBufferRef *inpicref)
     AVFilterBufferRef *outpicref = avfilter_ref_buffer(inpicref, ~0);
     int i;
 
+    if (!outpicref)
+        return AVERROR(ENOMEM);
+
     for (i = 0; i < 4; i ++) {
         int vsub = i == 1 || i == 2 ? flip->vsub : 0;
 
index 1025ba12c7dd2bc8f041a7f2adf7a7acfa4e03c5..db4956c2ccf7dd9cb3e9eeb651934d47f1ee8d06 100644 (file)
@@ -224,14 +224,18 @@ static int start_frame(AVFilterLink *link, AVFilterBufferRef *picref)
 
     if (yadif->auto_enable && !yadif->cur->video->interlaced) {
         yadif->out  = avfilter_ref_buffer(yadif->cur, AV_PERM_READ);
+        if (!yadif->out)
+            return AVERROR(ENOMEM);
+
         avfilter_unref_bufferp(&yadif->prev);
         if (yadif->out->pts != AV_NOPTS_VALUE)
             yadif->out->pts *= 2;
         return ff_start_frame(ctx->outputs[0], yadif->out);
     }
 
-    if (!yadif->prev)
-        yadif->prev = avfilter_ref_buffer(yadif->cur, AV_PERM_READ);
+    if (!yadif->prev &&
+        !(yadif->prev = avfilter_ref_buffer(yadif->cur, AV_PERM_READ)))
+        return AVERROR(ENOMEM);
 
     yadif->out = ff_get_video_buffer(ctx->outputs[0], AV_PERM_WRITE | AV_PERM_PRESERVE |
                                      AV_PERM_REUSE, link->w, link->h);
@@ -282,6 +286,9 @@ static int request_frame(AVFilterLink *link)
 
         if (ret == AVERROR_EOF && yadif->next) {
             AVFilterBufferRef *next = avfilter_ref_buffer(yadif->next, AV_PERM_READ);
+            if (!next)
+                return AVERROR(ENOMEM);
+
             next->pts = yadif->next->pts * 2 - yadif->cur->pts;
 
             start_frame(link->src->inputs[0], next);
index 8dd5bf4272b5bfa08326a93e8a6bdbe7e74b4f68..6e5063778a37678e74e6d4a5252b728698e75e35 100644 (file)
@@ -176,12 +176,17 @@ static int default_start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref)
         outlink = inlink->dst->outputs[0];
 
     if (outlink) {
+        AVFilterBufferRef *buf_out;
         outlink->out_buf = ff_get_video_buffer(outlink, AV_PERM_WRITE, outlink->w, outlink->h);
         if (!outlink->out_buf)
             return AVERROR(ENOMEM);
 
         avfilter_copy_buffer_ref_props(outlink->out_buf, picref);
-        return ff_start_frame(outlink, avfilter_ref_buffer(outlink->out_buf, ~0));
+        buf_out = avfilter_ref_buffer(outlink->out_buf, ~0);
+        if (!buf_out)
+            return AVERROR(ENOMEM);
+
+        return ff_start_frame(outlink, buf_out);
     }
     return 0;
 }
index c17f54f39d6c15b0a12e618c883238e423bc5dc1..0fa6853189410da746c5c77f64640b865d1d920e 100644 (file)
@@ -142,13 +142,20 @@ static int color_request_frame(AVFilterLink *link)
 {
     ColorContext *color = link->src->priv;
     AVFilterBufferRef *picref = ff_get_video_buffer(link, AV_PERM_WRITE, color->w, color->h);
+    AVFilterBufferRef *buf_out;
     int ret;
 
     picref->video->pixel_aspect = (AVRational) {1, 1};
     picref->pts                 = color->pts++;
     picref->pos                 = -1;
 
-    ret = ff_start_frame(link, avfilter_ref_buffer(picref, ~0));
+    buf_out = avfilter_ref_buffer(picref, ~0);
+    if (!buf_out) {
+        ret = AVERROR(ENOMEM);
+        goto fail;
+    }
+
+    ret = ff_start_frame(link, buf_out);
     if (ret < 0)
         goto fail;
 
index b0f191fe8e220decefc6a771513c683ea19c795f..926d57dff5da9ddc3733bff732c2a27a2998cdad 100644 (file)
@@ -289,6 +289,11 @@ static int request_frame(AVFilterLink *outlink)
         return ret;
 
     outpicref = avfilter_ref_buffer(movie->picref, ~0);
+    if (!outpicref) {
+        ret = AVERROR(ENOMEM);
+        goto fail;
+    }
+
     ret = ff_start_frame(outlink, outpicref);
     if (ret < 0)
         goto fail;