Browse code

avfilter/all: propagate errors of functions from avfilter/formats

Many of the functions from avfilter/formats can return errors, usually AVERROR(ENOMEM).
This propagates the return values.

All of these were found by using av_warn_unused_result, demonstrating its utility.

Tested with FATE. I am least sure of the changes to avfilter/filtergraph,
since I don't know what/how reduce_format is intended to behave and how it should
react to errors.

Fixes: CID 1325680, 1325679, 1325678.

Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Previous version Reviewed-by: Nicolas George <george@nsup.org>
Previous version Reviewed-by: Clément Bœsch <u@pkh.me>
Signed-off-by: Ganesh Ajjanagadde <gajjanagadde@gmail.com>

Ganesh Ajjanagadde authored on 2015/10/05 12:39:25
Showing 63 changed files
... ...
@@ -350,36 +350,34 @@ static int aeval_query_formats(AVFilterContext *ctx)
350 350
     static const enum AVSampleFormat sample_fmts[] = {
351 351
         AV_SAMPLE_FMT_DBLP, AV_SAMPLE_FMT_NONE
352 352
     };
353
+    int ret;
353 354
 
354 355
     // inlink supports any channel layout
355 356
     layouts = ff_all_channel_counts();
356
-    ff_channel_layouts_ref(layouts, &inlink->out_channel_layouts);
357
+    if ((ret = ff_channel_layouts_ref(layouts, &inlink->out_channel_layouts)) < 0)
358
+        return ret;
357 359
 
358 360
     if (eval->same_chlayout) {
359 361
         layouts = ff_all_channel_counts();
360
-        if (!layouts)
361
-            return AVERROR(ENOMEM);
362
-            ff_set_common_channel_layouts(ctx, layouts);
362
+        if ((ret = ff_set_common_channel_layouts(ctx, layouts)) < 0)
363
+            return ret;
363 364
     } else {
364 365
         // outlink supports only requested output channel layout
365 366
         layouts = NULL;
366
-        ff_add_channel_layout(&layouts,
367
+        if ((ret = ff_add_channel_layout(&layouts,
367 368
                               eval->out_channel_layout ? eval->out_channel_layout :
368
-                              FF_COUNT2LAYOUT(eval->nb_channels));
369
-        ff_channel_layouts_ref(layouts, &outlink->in_channel_layouts);
369
+                              FF_COUNT2LAYOUT(eval->nb_channels))) < 0)
370
+            return ret;
371
+        if ((ret = ff_channel_layouts_ref(layouts, &outlink->in_channel_layouts)) < 0)
372
+            return ret;
370 373
     }
371 374
 
372 375
     formats = ff_make_format_list(sample_fmts);
373
-    if (!formats)
374
-        return AVERROR(ENOMEM);
375
-    ff_set_common_formats(ctx, formats);
376
+    if ((ret = ff_set_common_formats(ctx, formats)) < 0)
377
+        return ret;
376 378
 
377 379
     formats = ff_all_samplerates();
378
-    if (!formats)
379
-        return AVERROR(ENOMEM);
380
-    ff_set_common_samplerates(ctx, formats);
381
-
382
-    return 0;
380
+    return ff_set_common_samplerates(ctx, formats);
383 381
 }
384 382
 
385 383
 static int aeval_config_output(AVFilterLink *outlink)
... ...
@@ -57,9 +57,10 @@ static const AVOption aformat_options[] = {
57 57
 
58 58
 AVFILTER_DEFINE_CLASS(aformat);
59 59
 
60
-#define PARSE_FORMATS(str, type, list, add_to_list, get_fmt, none, desc)    \
60
+#define PARSE_FORMATS(str, type, list, add_to_list, unref_fn, get_fmt, none, desc)    \
61 61
 do {                                                                        \
62 62
     char *next, *cur = str, sep;                                            \
63
+    int ret;                                                                \
63 64
                                                                             \
64 65
     if (str && strchr(str, ',')) {                                          \
65 66
         av_log(ctx, AV_LOG_WARNING, "This syntax is deprecated, use '|' to "\
... ...
@@ -78,7 +79,10 @@ do {                                                                        \
78 78
             av_log(ctx, AV_LOG_ERROR, "Error parsing " desc ": %s.\n", cur);\
79 79
             return AVERROR(EINVAL);                                         \
80 80
         }                                                                   \
81
-        add_to_list(&list, fmt);                                            \
81
+        if ((ret = add_to_list(&list, fmt)) < 0) {                          \
82
+            unref_fn(&list);                                                \
83
+            return ret;                                                     \
84
+        }                                                                   \
82 85
                                                                             \
83 86
         cur = next;                                                         \
84 87
     }                                                                       \
... ...
@@ -95,11 +99,11 @@ static av_cold int init(AVFilterContext *ctx)
95 95
     AFormatContext *s = ctx->priv;
96 96
 
97 97
     PARSE_FORMATS(s->formats_str, enum AVSampleFormat, s->formats,
98
-                  ff_add_format, av_get_sample_fmt, AV_SAMPLE_FMT_NONE, "sample format");
99
-    PARSE_FORMATS(s->sample_rates_str, int, s->sample_rates, ff_add_format,
98
+                  ff_add_format, ff_formats_unref, av_get_sample_fmt, AV_SAMPLE_FMT_NONE, "sample format");
99
+    PARSE_FORMATS(s->sample_rates_str, int, s->sample_rates, ff_add_format, ff_formats_unref,
100 100
                   get_sample_rate, 0, "sample rate");
101 101
     PARSE_FORMATS(s->channel_layouts_str, uint64_t, s->channel_layouts,
102
-                  ff_add_channel_layout, av_get_channel_layout, 0,
102
+                  ff_add_channel_layout, ff_channel_layouts_unref, av_get_channel_layout, 0,
103 103
                   "channel layout");
104 104
 
105 105
     return 0;
... ...
@@ -77,7 +77,8 @@ static int query_formats(AVFilterContext *ctx)
77 77
     AVFilterChannelLayouts *layouts;
78 78
     int ret;
79 79
 
80
-    ff_add_format(&formats, AV_SAMPLE_FMT_DBL);
80
+    if ((ret = ff_add_format(&formats, AV_SAMPLE_FMT_DBL)) < 0)
81
+        return ret;
81 82
     ret = ff_set_common_formats(ctx, formats);
82 83
     if (ret < 0)
83 84
         return ret;
... ...
@@ -78,7 +78,7 @@ static int query_formats(AVFilterContext *ctx)
78 78
     int64_t inlayout[SWR_CH_MAX], outlayout = 0;
79 79
     AVFilterFormats *formats;
80 80
     AVFilterChannelLayouts *layouts;
81
-    int i, overlap = 0, nb_ch = 0;
81
+    int i, ret, overlap = 0, nb_ch = 0;
82 82
 
83 83
     for (i = 0; i < s->nb_inputs; i++) {
84 84
         if (!ctx->inputs[i]->in_channel_layouts ||
... ...
@@ -125,17 +125,22 @@ static int query_formats(AVFilterContext *ctx)
125 125
                     *(route[i]++) = out_ch_number++;
126 126
     }
127 127
     formats = ff_make_format_list(ff_packed_sample_fmts_array);
128
-    ff_set_common_formats(ctx, formats);
128
+    if ((ret = ff_set_common_formats(ctx, formats)) < 0)
129
+        return ret;
129 130
     for (i = 0; i < s->nb_inputs; i++) {
130 131
         layouts = NULL;
131
-        ff_add_channel_layout(&layouts, inlayout[i]);
132
-        ff_channel_layouts_ref(layouts, &ctx->inputs[i]->out_channel_layouts);
132
+        if ((ret = ff_add_channel_layout(&layouts, inlayout[i])) < 0)
133
+            return ret;
134
+        if ((ret = ff_channel_layouts_ref(layouts, &ctx->inputs[i]->out_channel_layouts)) < 0)
135
+            return ret;
133 136
     }
134 137
     layouts = NULL;
135
-    ff_add_channel_layout(&layouts, outlayout);
136
-    ff_channel_layouts_ref(layouts, &ctx->outputs[0]->in_channel_layouts);
137
-    ff_set_common_samplerates(ctx, ff_all_samplerates());
138
-    return 0;
138
+    if ((ret = ff_add_channel_layout(&layouts, outlayout)) < 0)
139
+        return ret;
140
+    if ((ret = ff_channel_layouts_ref(layouts, &ctx->outputs[0]->in_channel_layouts)) < 0)
141
+        return ret;
142
+
143
+    return ff_set_common_samplerates(ctx, ff_all_samplerates());
139 144
 }
140 145
 
141 146
 static int config_output(AVFilterLink *outlink)
... ...
@@ -537,12 +537,13 @@ static int query_formats(AVFilterContext *ctx)
537 537
     int ret;
538 538
 
539 539
     layouts = ff_all_channel_layouts();
540
-
541 540
     if (!layouts)
542 541
         return AVERROR(ENOMEM);
543 542
 
544
-    ff_add_format(&formats, AV_SAMPLE_FMT_FLT);
545
-    ff_add_format(&formats, AV_SAMPLE_FMT_FLTP);
543
+    if ((ret = ff_add_format(&formats, AV_SAMPLE_FMT_FLT)) < 0)
544
+        return ret;
545
+    if ((ret = ff_add_format(&formats, AV_SAMPLE_FMT_FLTP)) < 0)
546
+        return ret;
546 547
     ret = ff_set_common_formats(ctx, formats);
547 548
     if (ret < 0)
548 549
         return ret;
... ...
@@ -88,25 +88,23 @@ static int query_formats(AVFilterContext *ctx)
88 88
     AVFilterFormats        *in_formats, *out_formats;
89 89
     AVFilterFormats        *in_samplerates, *out_samplerates;
90 90
     AVFilterChannelLayouts *in_layouts, *out_layouts;
91
+    int ret;
91 92
 
92 93
     av_opt_get_sample_fmt(aresample->swr, "osf", 0, &out_format);
93 94
     av_opt_get_int(aresample->swr, "osr", 0, &out_rate);
94 95
     av_opt_get_int(aresample->swr, "ocl", 0, &out_layout);
95 96
 
96 97
     in_formats      = ff_all_formats(AVMEDIA_TYPE_AUDIO);
97
-    if (!in_formats)
98
-        return AVERROR(ENOMEM);
99
-    ff_formats_ref  (in_formats,      &inlink->out_formats);
98
+    if ((ret = ff_formats_ref(in_formats, &inlink->out_formats)) < 0)
99
+        return ret;
100 100
 
101 101
     in_samplerates  = ff_all_samplerates();
102
-    if (!in_samplerates)
103
-        return AVERROR(ENOMEM);
104
-    ff_formats_ref  (in_samplerates,  &inlink->out_samplerates);
102
+    if ((ret = ff_formats_ref(in_samplerates, &inlink->out_samplerates)) < 0)
103
+        return ret;
105 104
 
106 105
     in_layouts      = ff_all_channel_counts();
107
-    if (!in_layouts)
108
-         return AVERROR(ENOMEM);
109
-    ff_channel_layouts_ref(in_layouts,      &inlink->out_channel_layouts);
106
+    if ((ret = ff_channel_layouts_ref(in_layouts, &inlink->out_channel_layouts)) < 0)
107
+        return ret;
110 108
 
111 109
     if(out_rate > 0) {
112 110
         int ratelist[] = { out_rate, -1 };
... ...
@@ -114,28 +112,25 @@ static int query_formats(AVFilterContext *ctx)
114 114
     } else {
115 115
         out_samplerates = ff_all_samplerates();
116 116
     }
117
-    if (!out_samplerates) {
118
-        av_log(ctx, AV_LOG_ERROR, "Cannot allocate output samplerates.\n");
119
-        return AVERROR(ENOMEM);
120
-    }
121 117
 
122
-    ff_formats_ref(out_samplerates, &outlink->in_samplerates);
118
+    if ((ret = ff_formats_ref(out_samplerates, &outlink->in_samplerates)) < 0)
119
+        return ret;
123 120
 
124 121
     if(out_format != AV_SAMPLE_FMT_NONE) {
125 122
         int formatlist[] = { out_format, -1 };
126 123
         out_formats = ff_make_format_list(formatlist);
127 124
     } else
128 125
         out_formats = ff_all_formats(AVMEDIA_TYPE_AUDIO);
129
-    ff_formats_ref(out_formats, &outlink->in_formats);
126
+    if ((ret = ff_formats_ref(out_formats, &outlink->in_formats)) < 0)
127
+        return ret;
130 128
 
131 129
     if(out_layout) {
132 130
         int64_t layout_list[] = { out_layout, -1 };
133 131
         out_layouts = avfilter_make_format64_list(layout_list);
134 132
     } else
135 133
         out_layouts = ff_all_channel_counts();
136
-    ff_channel_layouts_ref(out_layouts, &outlink->in_channel_layouts);
137 134
 
138
-    return 0;
135
+    return ff_channel_layouts_ref(out_layouts, &outlink->in_channel_layouts);
139 136
 }
140 137
 
141 138
 
... ...
@@ -89,20 +89,23 @@ static av_cold int init(AVFilterContext *ctx)
89 89
 
90 90
 static int query_formats(AVFilterContext *ctx)
91 91
 {
92
-    int i;
92
+    int i, ret;
93 93
     AVFilterFormats *formats, *rates;
94 94
     AVFilterChannelLayouts *layouts;
95 95
 
96 96
     for (i = 0; i < 2; i++) {
97 97
         formats = ctx->inputs[i]->in_formats;
98
-        ff_formats_ref(formats, &ctx->inputs[i]->out_formats);
99
-        ff_formats_ref(formats, &ctx->outputs[i]->in_formats);
98
+        if ((ret = ff_formats_ref(formats, &ctx->inputs[i]->out_formats)) < 0 ||
99
+            (ret = ff_formats_ref(formats, &ctx->outputs[i]->in_formats)) < 0)
100
+            return ret;
100 101
         rates = ff_all_samplerates();
101
-        ff_formats_ref(rates, &ctx->inputs[i]->out_samplerates);
102
-        ff_formats_ref(rates, &ctx->outputs[i]->in_samplerates);
102
+        if ((ret = ff_formats_ref(rates, &ctx->inputs[i]->out_samplerates)) < 0 ||
103
+            (ret = ff_formats_ref(rates, &ctx->outputs[i]->in_samplerates)) < 0)
104
+            return ret;
103 105
         layouts = ctx->inputs[i]->in_channel_layouts;
104
-        ff_channel_layouts_ref(layouts, &ctx->inputs[i]->out_channel_layouts);
105
-        ff_channel_layouts_ref(layouts, &ctx->outputs[i]->in_channel_layouts);
106
+        if ((ret = ff_channel_layouts_ref(layouts, &ctx->inputs[i]->out_channel_layouts)) < 0 ||
107
+            (ret = ff_channel_layouts_ref(layouts, &ctx->outputs[i]->in_channel_layouts)) < 0)
108
+            return ret;
106 109
     }
107 110
     return 0;
108 111
 }
... ...
@@ -289,18 +289,15 @@ static int channelmap_query_formats(AVFilterContext *ctx)
289 289
     ChannelMapContext *s = ctx->priv;
290 290
     AVFilterChannelLayouts *layouts;
291 291
     AVFilterChannelLayouts *channel_layouts = NULL;
292
+    int ret;
292 293
 
293 294
     layouts = ff_all_channel_layouts();
294
-    if (!layouts)
295
-        return AVERROR(ENOMEM);
296
-
297
-    ff_add_channel_layout(&channel_layouts, s->output_layout);
298
-
299
-    ff_set_common_formats(ctx, ff_planar_sample_fmts());
300
-    ff_set_common_samplerates(ctx, ff_all_samplerates());
301
-
302
-    ff_channel_layouts_ref(layouts, &ctx->inputs[0]->out_channel_layouts);
303
-    ff_channel_layouts_ref(channel_layouts,          &ctx->outputs[0]->in_channel_layouts);
295
+    if ((ret = ff_add_channel_layout     (&channel_layouts, s->output_layout                    )) < 0 ||
296
+        (ret = ff_set_common_formats     (ctx             , ff_planar_sample_fmts()             )) < 0 ||
297
+        (ret = ff_set_common_samplerates (ctx             , ff_all_samplerates()                )) < 0 ||
298
+        (ret = ff_channel_layouts_ref    (layouts         , &ctx->inputs[0]->out_channel_layouts)) < 0 ||
299
+        (ret = ff_channel_layouts_ref    (channel_layouts , &ctx->outputs[0]->in_channel_layouts)) < 0)
300
+        return ret;
304 301
 
305 302
     return 0;
306 303
 }
... ...
@@ -82,20 +82,23 @@ static int query_formats(AVFilterContext *ctx)
82 82
 {
83 83
     ChannelSplitContext *s = ctx->priv;
84 84
     AVFilterChannelLayouts *in_layouts = NULL;
85
-    int i;
85
+    int i, ret;
86 86
 
87
-    ff_set_common_formats    (ctx, ff_planar_sample_fmts());
88
-    ff_set_common_samplerates(ctx, ff_all_samplerates());
87
+    if ((ret = ff_set_common_formats(ctx, ff_planar_sample_fmts())) < 0 ||
88
+        (ret = ff_set_common_samplerates(ctx, ff_all_samplerates())) < 0)
89
+        return ret;
89 90
 
90
-    ff_add_channel_layout(&in_layouts, s->channel_layout);
91
-    ff_channel_layouts_ref(in_layouts, &ctx->inputs[0]->out_channel_layouts);
91
+    if ((ret = ff_add_channel_layout(&in_layouts, s->channel_layout)) < 0 ||
92
+        (ret = ff_channel_layouts_ref(in_layouts, &ctx->inputs[0]->out_channel_layouts)) < 0)
93
+        return ret;
92 94
 
93 95
     for (i = 0; i < ctx->nb_outputs; i++) {
94 96
         AVFilterChannelLayouts *out_layouts = NULL;
95 97
         uint64_t channel = av_channel_layout_extract_channel(s->channel_layout, i);
96 98
 
97
-        ff_add_channel_layout(&out_layouts, channel);
98
-        ff_channel_layouts_ref(out_layouts, &ctx->outputs[i]->in_channel_layouts);
99
+        if ((ret = ff_add_channel_layout(&out_layouts, channel)) < 0 ||
100
+            (ret = ff_channel_layouts_ref(out_layouts, &ctx->outputs[i]->in_channel_layouts)) < 0)
101
+            return ret;
99 102
     }
100 103
 
101 104
     return 0;
... ...
@@ -78,15 +78,17 @@ typedef struct {
78 78
 static int query_formats(AVFilterContext *ctx)
79 79
 {
80 80
     static const int sample_rates[] = { 44100, -1 };
81
+    int ret;
81 82
 
82 83
     AVFilterFormats *formats = NULL;
83 84
     AVFilterChannelLayouts *layout = NULL;
84 85
 
85
-    ff_add_format(&formats, AV_SAMPLE_FMT_S16);
86
-    ff_set_common_formats(ctx, formats);
87
-    ff_add_channel_layout(&layout, AV_CH_LAYOUT_STEREO);
88
-    ff_set_common_channel_layouts(ctx, layout);
89
-    ff_set_common_samplerates(ctx, ff_make_format_list(sample_rates));
86
+    if ((ret = ff_add_format                 (&formats, AV_SAMPLE_FMT_S16                 )) < 0 ||
87
+        (ret = ff_set_common_formats         (ctx     , formats                           )) < 0 ||
88
+        (ret = ff_add_channel_layout         (&layout , AV_CH_LAYOUT_STEREO               )) < 0 ||
89
+        (ret = ff_set_common_channel_layouts (ctx     , layout                            )) < 0 ||
90
+        (ret = ff_set_common_samplerates     (ctx     , ff_make_format_list(sample_rates) )) < 0)
91
+        return ret;
90 92
 
91 93
     return 0;
92 94
 }
... ...
@@ -45,15 +45,15 @@ static int query_formats(AVFilterContext *ctx)
45 45
 {
46 46
     AVFilterFormats *formats = NULL;
47 47
     AVFilterChannelLayouts *layout = NULL;
48
+    int ret;
48 49
 
49
-    ff_add_format(&formats, AV_SAMPLE_FMT_FLT);
50
-    ff_set_common_formats(ctx, formats);
51
-    ff_add_channel_layout(&layout, AV_CH_LAYOUT_STEREO);
52
-    ff_set_common_channel_layouts(ctx, layout);
50
+    if ((ret = ff_add_format                 (&formats, AV_SAMPLE_FMT_FLT  )) < 0 ||
51
+        (ret = ff_set_common_formats         (ctx     , formats            )) < 0 ||
52
+        (ret = ff_add_channel_layout         (&layout , AV_CH_LAYOUT_STEREO)) < 0 ||
53
+        (ret = ff_set_common_channel_layouts (ctx     , layout             )) < 0)
54
+        return ret;
53 55
 
54 56
     formats = ff_all_samplerates();
55
-    if (!formats)
56
-        return AVERROR(ENOMEM);
57 57
     return ff_set_common_samplerates(ctx, formats);
58 58
 }
59 59
 
... ...
@@ -245,20 +245,21 @@ static int join_query_formats(AVFilterContext *ctx)
245 245
 {
246 246
     JoinContext *s = ctx->priv;
247 247
     AVFilterChannelLayouts *layouts = NULL;
248
-    int i;
248
+    int i, ret;
249 249
 
250
-    ff_add_channel_layout(&layouts, s->channel_layout);
251
-    ff_channel_layouts_ref(layouts, &ctx->outputs[0]->in_channel_layouts);
250
+    if ((ret = ff_add_channel_layout(&layouts, s->channel_layout)) < 0 ||
251
+        (ret = ff_channel_layouts_ref(layouts, &ctx->outputs[0]->in_channel_layouts)) < 0)
252
+        return ret;
252 253
 
253 254
     for (i = 0; i < ctx->nb_inputs; i++) {
254 255
         layouts = ff_all_channel_layouts();
255
-        if (!layouts)
256
-            return AVERROR(ENOMEM);
257
-        ff_channel_layouts_ref(layouts, &ctx->inputs[i]->out_channel_layouts);
256
+        if ((ret = ff_channel_layouts_ref(layouts, &ctx->inputs[i]->out_channel_layouts)) < 0)
257
+            return ret;
258 258
     }
259 259
 
260
-    ff_set_common_formats    (ctx, ff_planar_sample_fmts());
261
-    ff_set_common_samplerates(ctx, ff_all_samplerates());
260
+    if ((ret = ff_set_common_formats(ctx, ff_planar_sample_fmts())) < 0 ||
261
+        (ret = ff_set_common_samplerates(ctx, ff_all_samplerates())) < 0)
262
+        return ret;
262 263
 
263 264
     return 0;
264 265
 }
... ...
@@ -227,27 +227,29 @@ static int query_formats(AVFilterContext *ctx)
227 227
     AVFilterLink *outlink = ctx->outputs[0];
228 228
     AVFilterFormats *formats = NULL;
229 229
     AVFilterChannelLayouts *layouts;
230
+    int ret;
230 231
 
231 232
     pan->pure_gains = are_gains_pure(pan);
232 233
     /* libswr supports any sample and packing formats */
233
-    ff_set_common_formats(ctx, ff_all_formats(AVMEDIA_TYPE_AUDIO));
234
+    if ((ret = ff_set_common_formats(ctx, ff_all_formats(AVMEDIA_TYPE_AUDIO))) < 0)
235
+        return ret;
234 236
 
235 237
     formats = ff_all_samplerates();
236
-    if (!formats)
237
-        return AVERROR(ENOMEM);
238
-    ff_set_common_samplerates(ctx, formats);
238
+    if ((ret = ff_set_common_samplerates(ctx, formats)) < 0)
239
+        return ret;
239 240
 
240 241
     // inlink supports any channel layout
241 242
     layouts = ff_all_channel_counts();
242
-    ff_channel_layouts_ref(layouts, &inlink->out_channel_layouts);
243
+    if ((ret = ff_channel_layouts_ref(layouts, &inlink->out_channel_layouts)) < 0)
244
+        return ret;
243 245
 
244 246
     // outlink supports only requested output channel layout
245 247
     layouts = NULL;
246
-    ff_add_channel_layout(&layouts,
248
+    if ((ret = ff_add_channel_layout(&layouts,
247 249
                           pan->out_channel_layout ? pan->out_channel_layout :
248
-                          FF_COUNT2LAYOUT(pan->nb_output_channels));
249
-    ff_channel_layouts_ref(layouts, &outlink->in_channel_layouts);
250
-    return 0;
250
+                          FF_COUNT2LAYOUT(pan->nb_output_channels))) < 0)
251
+        return ret;
252
+    return ff_channel_layouts_ref(layouts, &outlink->in_channel_layouts);
251 253
 }
252 254
 
253 255
 static int config_props(AVFilterLink *link)
... ...
@@ -323,19 +323,21 @@ static int query_formats(AVFilterContext *ctx)
323 323
 {
324 324
     AVFilterFormats *formats = NULL;
325 325
     AVFilterChannelLayouts *layout = NULL;
326
-    int i;
326
+    int i, ret;
327 327
 
328
-    ff_add_format(&formats, AV_SAMPLE_FMT_FLT);
329
-    ff_set_common_formats(ctx, formats);
330
-    ff_add_channel_layout(&layout, AV_CH_LAYOUT_STEREO);
331
-    ff_set_common_channel_layouts(ctx, layout);
328
+    if ((ret = ff_add_format                 (&formats, AV_SAMPLE_FMT_FLT  )) < 0 ||
329
+        (ret = ff_set_common_formats         (ctx     , formats            )) < 0 ||
330
+        (ret = ff_add_channel_layout         (&layout , AV_CH_LAYOUT_STEREO)) < 0 ||
331
+        (ret = ff_set_common_channel_layouts (ctx     , layout             )) < 0)
332
+        return ret;
332 333
 
333 334
     formats = NULL;
334
-    for (i = 0; i < FF_ARRAY_ELEMS(freqinfos); i++)
335
-        ff_add_format(&formats, freqinfos[i].sample_rate);
336
-    ff_set_common_samplerates(ctx, formats);
335
+    for (i = 0; i < FF_ARRAY_ELEMS(freqinfos); i++) {
336
+        if ((ret = ff_add_format(&formats, freqinfos[i].sample_rate)) < 0)
337
+            return ret;
338
+    }
337 339
 
338
-    return 0;
340
+    return ff_set_common_samplerates(ctx, formats);
339 341
 }
340 342
 
341 343
 static int config_input(AVFilterLink *inlink)
... ...
@@ -90,22 +90,25 @@ static int query_formats(AVFilterContext *ctx)
90 90
 {
91 91
     AVFilterLink *inlink  = ctx->inputs[0];
92 92
     AVFilterLink *outlink = ctx->outputs[0];
93
+    AVFilterFormats *in_formats, *out_formats, *in_samplerates, *out_samplerates;
94
+    AVFilterChannelLayouts *in_layouts, *out_layouts;
95
+    int ret;
93 96
 
94
-    AVFilterFormats        *in_formats      = ff_all_formats(AVMEDIA_TYPE_AUDIO);
95
-    AVFilterFormats        *out_formats     = ff_all_formats(AVMEDIA_TYPE_AUDIO);
96
-    AVFilterFormats        *in_samplerates  = ff_all_samplerates();
97
-    AVFilterFormats        *out_samplerates = ff_all_samplerates();
98
-    AVFilterChannelLayouts *in_layouts      = ff_all_channel_layouts();
99
-    AVFilterChannelLayouts *out_layouts     = ff_all_channel_layouts();
100
-
101
-    ff_formats_ref(in_formats,  &inlink->out_formats);
102
-    ff_formats_ref(out_formats, &outlink->in_formats);
103
-
104
-    ff_formats_ref(in_samplerates,  &inlink->out_samplerates);
105
-    ff_formats_ref(out_samplerates, &outlink->in_samplerates);
97
+    if (!(in_formats      = ff_all_formats         (AVMEDIA_TYPE_AUDIO)) ||
98
+        !(out_formats     = ff_all_formats         (AVMEDIA_TYPE_AUDIO)) ||
99
+        !(in_samplerates  = ff_all_samplerates     (                  )) ||
100
+        !(out_samplerates = ff_all_samplerates     (                  )) ||
101
+        !(in_layouts      = ff_all_channel_layouts (                  )) ||
102
+        !(out_layouts     = ff_all_channel_layouts (                  )))
103
+        return AVERROR(ENOMEM);
106 104
 
107
-    ff_channel_layouts_ref(in_layouts,  &inlink->out_channel_layouts);
108
-    ff_channel_layouts_ref(out_layouts, &outlink->in_channel_layouts);
105
+    if ((ret = ff_formats_ref         (in_formats,      &inlink->out_formats        )) < 0 ||
106
+        (ret = ff_formats_ref         (out_formats,     &outlink->in_formats        )) < 0 ||
107
+        (ret = ff_formats_ref         (in_samplerates,  &inlink->out_samplerates    )) < 0 ||
108
+        (ret = ff_formats_ref         (out_samplerates, &outlink->in_samplerates    )) < 0 ||
109
+        (ret = ff_channel_layouts_ref (in_layouts,      &inlink->out_channel_layouts)) < 0 ||
110
+        (ret = ff_channel_layouts_ref (out_layouts,     &outlink->in_channel_layouts)) < 0)
111
+        return ret;
109 112
 
110 113
     return 0;
111 114
 }
... ...
@@ -229,28 +229,21 @@ static int query_formats(AVFilterContext *ctx)
229 229
             return AVERROR(EAGAIN);
230 230
     }
231 231
 
232
-    ff_add_channel_layout(&layouts, ctx->inputs[0]->in_channel_layouts->channel_layouts[0]);
233
-    if (!layouts)
234
-        return AVERROR(ENOMEM);
235
-    ff_channel_layouts_ref(layouts, &ctx->outputs[0]->in_channel_layouts);
232
+    if ((ret = ff_add_channel_layout(&layouts, ctx->inputs[0]->in_channel_layouts->channel_layouts[0])) < 0 ||
233
+        (ret = ff_channel_layouts_ref(layouts, &ctx->outputs[0]->in_channel_layouts)) < 0)
234
+        return ret;
236 235
 
237 236
     for (i = 0; i < 2; i++) {
238 237
         layouts = ff_all_channel_counts();
239
-        if (!layouts)
240
-            return AVERROR(ENOMEM);
241
-        ff_channel_layouts_ref(layouts, &ctx->inputs[i]->out_channel_layouts);
238
+        if ((ret = ff_channel_layouts_ref(layouts, &ctx->inputs[i]->out_channel_layouts)) < 0)
239
+            return ret;
242 240
     }
243 241
 
244 242
     formats = ff_make_format_list(sample_fmts);
245
-    if (!formats)
246
-        return AVERROR(ENOMEM);
247
-    ret = ff_set_common_formats(ctx, formats);
248
-    if (ret < 0)
243
+    if ((ret = ff_set_common_formats(ctx, formats)) < 0)
249 244
         return ret;
250 245
 
251 246
     formats = ff_all_samplerates();
252
-    if (!formats)
253
-        return AVERROR(ENOMEM);
254 247
     return ff_set_common_samplerates(ctx, formats);
255 248
 }
256 249
 
... ...
@@ -92,16 +92,15 @@ static int query_formats(AVFilterContext *ctx)
92 92
 {
93 93
     AVFilterFormats *formats = NULL;
94 94
     AVFilterChannelLayouts *layout = NULL;
95
+    int ret;
95 96
 
96
-    ff_add_format(&formats, AV_SAMPLE_FMT_DBL);
97
-    ff_set_common_formats(ctx, formats);
98
-    ff_add_channel_layout(&layout, AV_CH_LAYOUT_STEREO);
99
-    ff_set_common_channel_layouts(ctx, layout);
97
+    if ((ret = ff_add_format                 (&formats, AV_SAMPLE_FMT_DBL  )) < 0 ||
98
+        (ret = ff_set_common_formats         (ctx     , formats            )) < 0 ||
99
+        (ret = ff_add_channel_layout         (&layout , AV_CH_LAYOUT_STEREO)) < 0 ||
100
+        (ret = ff_set_common_channel_layouts (ctx     , layout             )) < 0)
101
+        return ret;
100 102
 
101 103
     formats = ff_all_samplerates();
102
-    if (!formats)
103
-        return AVERROR(ENOMEM);
104
-
105 104
     return ff_set_common_samplerates(ctx, formats);
106 105
 }
107 106
 
... ...
@@ -55,15 +55,15 @@ static int query_formats(AVFilterContext *ctx)
55 55
 {
56 56
     AVFilterFormats *formats = NULL;
57 57
     AVFilterChannelLayouts *layout = NULL;
58
+    int ret;
58 59
 
59
-    ff_add_format(&formats, AV_SAMPLE_FMT_FLT);
60
-    ff_set_common_formats(ctx, formats);
61
-    ff_add_channel_layout(&layout, AV_CH_LAYOUT_STEREO);
62
-    ff_set_common_channel_layouts(ctx, layout);
60
+    if ((ret = ff_add_format                 (&formats, AV_SAMPLE_FMT_FLT  )) < 0 ||
61
+        (ret = ff_set_common_formats         (ctx     , formats            )) < 0 ||
62
+        (ret = ff_add_channel_layout         (&layout , AV_CH_LAYOUT_STEREO)) < 0 ||
63
+        (ret = ff_set_common_channel_layouts (ctx     , layout             )) < 0)
64
+        return ret;
63 65
 
64 66
     formats = ff_all_samplerates();
65
-    if (!formats)
66
-        return AVERROR(ENOMEM);
67 67
     return ff_set_common_samplerates(ctx, formats);
68 68
 }
69 69
 
... ...
@@ -80,10 +80,12 @@ static int query_formats(AVFilterContext *ctx)
80 80
     ANullContext *null = ctx->priv;
81 81
     int64_t chlayouts[] = { null->channel_layout, -1 };
82 82
     int sample_rates[] = { null->sample_rate, -1 };
83
+    int ret;
83 84
 
84
-    ff_set_common_formats        (ctx, ff_all_formats(AVMEDIA_TYPE_AUDIO));
85
-    ff_set_common_channel_layouts(ctx, avfilter_make_format64_list(chlayouts));
86
-    ff_set_common_samplerates    (ctx, ff_make_format_list(sample_rates));
85
+    if ((ret = ff_set_common_formats         (ctx, ff_all_formats              (AVMEDIA_TYPE_AUDIO))) < 0 ||
86
+        (ret = ff_set_common_channel_layouts (ctx, avfilter_make_format64_list (chlayouts         ))) < 0 ||
87
+        (ret = ff_set_common_samplerates     (ctx, ff_make_format_list         (sample_rates      ))) < 0)
88
+        return ret;
87 89
 
88 90
     return 0;
89 91
 }
... ...
@@ -205,18 +205,20 @@ static av_cold void uninit(AVFilterContext *ctx)
205 205
 static int query_formats(AVFilterContext *ctx)
206 206
 {
207 207
     FliteContext *flite = ctx->priv;
208
+    int ret;
208 209
 
209 210
     AVFilterChannelLayouts *chlayouts = NULL;
210 211
     int64_t chlayout = av_get_default_channel_layout(flite->wave->num_channels);
211 212
     AVFilterFormats *sample_formats = NULL;
212 213
     AVFilterFormats *sample_rates = NULL;
213 214
 
214
-    ff_add_channel_layout(&chlayouts, chlayout);
215
-    ff_set_common_channel_layouts(ctx, chlayouts);
216
-    ff_add_format(&sample_formats, AV_SAMPLE_FMT_S16);
217
-    ff_set_common_formats(ctx, sample_formats);
218
-    ff_add_format(&sample_rates, flite->wave->sample_rate);
219
-    ff_set_common_samplerates (ctx, sample_rates);
215
+    if ((ret = ff_add_channel_layout         (&chlayouts     , chlayout                )) < 0 ||
216
+        (ret = ff_set_common_channel_layouts (ctx            , chlayouts               )) < 0 ||
217
+        (ret = ff_add_format                 (&sample_formats, AV_SAMPLE_FMT_S16       )) < 0 ||
218
+        (ret = ff_set_common_formats         (ctx            , sample_formats          )) < 0 ||
219
+        (ret = ff_add_format                 (&sample_rates  , flite->wave->sample_rate)) < 0 ||
220
+        (ret = ff_set_common_samplerates     (ctx            , sample_rates            )) < 0)
221
+        return ret;
220 222
 
221 223
     return 0;
222 224
 }
... ...
@@ -70,24 +70,21 @@ static int query_formats(AVFilterContext *ctx)
70 70
     AVFilterLink *outlink = ctx->outputs[0];
71 71
     static const enum AVSampleFormat sample_fmts[] = { AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_NONE };
72 72
     static const enum AVPixelFormat pix_fmts[] = { AV_PIX_FMT_RGBA, AV_PIX_FMT_NONE };
73
+    int ret;
73 74
 
74 75
     formats = ff_make_format_list(sample_fmts);
75
-    if (!formats)
76
-        return AVERROR(ENOMEM);
77
-    ff_formats_ref(formats, &inlink->out_formats);
78
-
79
-    ff_add_channel_layout(&layout, AV_CH_LAYOUT_STEREO);
80
-    ff_channel_layouts_ref(layout, &inlink->out_channel_layouts);
76
+    if ((ret = ff_formats_ref         (formats, &inlink->out_formats        )) < 0 ||
77
+        (ret = ff_add_channel_layout  (&layout, AV_CH_LAYOUT_STEREO         )) < 0 ||
78
+        (ret = ff_channel_layouts_ref (layout , &inlink->out_channel_layouts)) < 0)
79
+        return ret;
81 80
 
82 81
     formats = ff_all_samplerates();
83
-    if (!formats)
84
-        return AVERROR(ENOMEM);
85
-    ff_formats_ref(formats, &inlink->out_samplerates);
82
+    if ((ret = ff_formats_ref(formats, &inlink->out_samplerates)) < 0)
83
+        return ret;
86 84
 
87 85
     formats = ff_make_format_list(pix_fmts);
88
-    if (!formats)
89
-        return AVERROR(ENOMEM);
90
-    ff_formats_ref(formats, &outlink->in_formats);
86
+    if ((ret = ff_formats_ref(formats, &outlink->in_formats)) < 0)
87
+        return ret;
91 88
 
92 89
     return 0;
93 90
 }
... ...
@@ -126,24 +126,21 @@ static int query_formats(AVFilterContext *ctx)
126 126
     AVFilterLink *outlink = ctx->outputs[0];
127 127
     static const enum AVSampleFormat sample_fmts[] = { AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_NONE };
128 128
     static const enum AVPixelFormat pix_fmts[] = { AV_PIX_FMT_RGBA, AV_PIX_FMT_NONE };
129
+    int ret;
129 130
 
130 131
     formats = ff_make_format_list(sample_fmts);
131
-    if (!formats)
132
-        return AVERROR(ENOMEM);
133
-    ff_formats_ref(formats, &inlink->out_formats);
134
-
135
-    ff_add_channel_layout(&layout, AV_CH_LAYOUT_STEREO);
136
-    ff_channel_layouts_ref(layout, &inlink->out_channel_layouts);
132
+    if ((ret = ff_formats_ref         (formats, &inlink->out_formats        )) < 0 ||
133
+        (ret = ff_add_channel_layout  (&layout, AV_CH_LAYOUT_STEREO         )) < 0 ||
134
+        (ret = ff_channel_layouts_ref (layout , &inlink->out_channel_layouts)) < 0)
135
+        return ret;
137 136
 
138 137
     formats = ff_all_samplerates();
139
-    if (!formats)
140
-        return AVERROR(ENOMEM);
141
-    ff_formats_ref(formats, &inlink->out_samplerates);
138
+    if ((ret = ff_formats_ref(formats, &inlink->out_samplerates)) < 0)
139
+        return ret;
142 140
 
143 141
     formats = ff_make_format_list(pix_fmts);
144
-    if (!formats)
145
-        return AVERROR(ENOMEM);
146
-    ff_formats_ref(formats, &outlink->in_formats);
142
+    if ((ret = ff_formats_ref(formats, &outlink->in_formats)) < 0)
143
+        return ret;
147 144
 
148 145
     return 0;
149 146
 }
... ...
@@ -80,6 +80,7 @@ static int query_formats(AVFilterContext *ctx)
80 80
     unsigned type, nb_str, idx0 = 0, idx, str, seg;
81 81
     AVFilterFormats *formats, *rates = NULL;
82 82
     AVFilterChannelLayouts *layouts = NULL;
83
+    int ret;
83 84
 
84 85
     for (type = 0; type < TYPE_ALL; type++) {
85 86
         nb_str = cat->nb_streams[type];
... ...
@@ -88,26 +89,26 @@ static int query_formats(AVFilterContext *ctx)
88 88
 
89 89
             /* Set the output formats */
90 90
             formats = ff_all_formats(type);
91
-            if (!formats)
92
-                return AVERROR(ENOMEM);
93
-            ff_formats_ref(formats, &ctx->outputs[idx]->in_formats);
91
+            if ((ret = ff_formats_ref(formats, &ctx->outputs[idx]->in_formats)) < 0)
92
+                return ret;
93
+
94 94
             if (type == AVMEDIA_TYPE_AUDIO) {
95 95
                 rates = ff_all_samplerates();
96
-                if (!rates)
97
-                    return AVERROR(ENOMEM);
98
-                ff_formats_ref(rates, &ctx->outputs[idx]->in_samplerates);
96
+                if ((ret = ff_formats_ref(rates, &ctx->outputs[idx]->in_samplerates)) < 0)
97
+                    return ret;
99 98
                 layouts = ff_all_channel_layouts();
100
-                if (!layouts)
101
-                    return AVERROR(ENOMEM);
102
-                ff_channel_layouts_ref(layouts, &ctx->outputs[idx]->in_channel_layouts);
99
+                if ((ret = ff_channel_layouts_ref(layouts, &ctx->outputs[idx]->in_channel_layouts)) < 0)
100
+                    return ret;
103 101
             }
104 102
 
105 103
             /* Set the same formats for each corresponding input */
106 104
             for (seg = 0; seg < cat->nb_segments; seg++) {
107
-                ff_formats_ref(formats, &ctx->inputs[idx]->out_formats);
105
+                if ((ret = ff_formats_ref(formats, &ctx->inputs[idx]->out_formats)) < 0)
106
+                    return ret;
108 107
                 if (type == AVMEDIA_TYPE_AUDIO) {
109
-                    ff_formats_ref(rates, &ctx->inputs[idx]->out_samplerates);
110
-                    ff_channel_layouts_ref(layouts, &ctx->inputs[idx]->out_channel_layouts);
108
+                    if ((ret = ff_formats_ref(rates, &ctx->inputs[idx]->out_samplerates)) < 0 ||
109
+                        (ret = ff_channel_layouts_ref(layouts, &ctx->inputs[idx]->out_channel_layouts)) < 0)
110
+                        return ret;
111 111
                 }
112 112
                 idx += ctx->nb_outputs;
113 113
             }
... ...
@@ -136,28 +136,25 @@ static int query_formats(AVFilterContext *ctx)
136 136
     static const enum AVPixelFormat pix_fmts[] = { AV_PIX_FMT_RGB24, AV_PIX_FMT_NONE };
137 137
     static const int64_t channel_layouts[] = { AV_CH_LAYOUT_STEREO, AV_CH_LAYOUT_STEREO_DOWNMIX, -1 };
138 138
     static const int samplerates[] = { 44100, 48000, -1 };
139
+    int ret;
139 140
 
140 141
     /* set input audio formats */
141 142
     formats = ff_make_format_list(sample_fmts);
142
-    if (!formats)
143
-        return AVERROR(ENOMEM);
144
-    ff_formats_ref(formats, &inlink->out_formats);
143
+    if ((ret = ff_formats_ref(formats, &inlink->out_formats)) < 0)
144
+        return ret;
145 145
 
146 146
     layouts = avfilter_make_format64_list(channel_layouts);
147
-    if (!layouts)
148
-        return AVERROR(ENOMEM);
149
-    ff_channel_layouts_ref(layouts, &inlink->out_channel_layouts);
147
+    if ((ret = ff_channel_layouts_ref(layouts, &inlink->out_channel_layouts)) < 0)
148
+        return ret;
150 149
 
151 150
     formats = ff_make_format_list(samplerates);
152
-    if (!formats)
153
-        return AVERROR(ENOMEM);
154
-    ff_formats_ref(formats, &inlink->out_samplerates);
151
+    if ((ret = ff_formats_ref(formats, &inlink->out_samplerates)) < 0)
152
+        return ret;
155 153
 
156 154
     /* set output video format */
157 155
     formats = ff_make_format_list(pix_fmts);
158
-    if (!formats)
159
-        return AVERROR(ENOMEM);
160
-    ff_formats_ref(formats, &outlink->in_formats);
156
+    if ((ret = ff_formats_ref(formats, &outlink->in_formats)) < 0)
157
+        return ret;
161 158
 
162 159
     return 0;
163 160
 }
... ...
@@ -128,28 +128,25 @@ static int query_formats(AVFilterContext *ctx)
128 128
     AVFilterLink *outlink = ctx->outputs[0];
129 129
     static const enum AVSampleFormat sample_fmts[] = { AV_SAMPLE_FMT_FLTP, AV_SAMPLE_FMT_NONE };
130 130
     static const enum AVPixelFormat pix_fmts[] = { AV_PIX_FMT_RGBA, AV_PIX_FMT_NONE };
131
+    int ret;
131 132
 
132 133
     /* set input audio formats */
133 134
     formats = ff_make_format_list(sample_fmts);
134
-    if (!formats)
135
-        return AVERROR(ENOMEM);
136
-    ff_formats_ref(formats, &inlink->out_formats);
135
+    if ((ret = ff_formats_ref(formats, &inlink->out_formats)) < 0)
136
+        return ret;
137 137
 
138 138
     layouts = ff_all_channel_layouts();
139
-    if (!layouts)
140
-        return AVERROR(ENOMEM);
141
-    ff_channel_layouts_ref(layouts, &inlink->out_channel_layouts);
139
+    if ((ret = ff_channel_layouts_ref(layouts, &inlink->out_channel_layouts)) < 0)
140
+        return ret;
142 141
 
143 142
     formats = ff_all_samplerates();
144
-    if (!formats)
145
-        return AVERROR(ENOMEM);
146
-    ff_formats_ref(formats, &inlink->out_samplerates);
143
+    if ((ret = ff_formats_ref(formats, &inlink->out_samplerates)) < 0)
144
+        return ret;
147 145
 
148 146
     /* set output video format */
149 147
     formats = ff_make_format_list(pix_fmts);
150
-    if (!formats)
151
-        return AVERROR(ENOMEM);
152
-    ff_formats_ref(formats, &outlink->in_formats);
148
+    if ((ret = ff_formats_ref(formats, &outlink->in_formats)) < 0)
149
+        return ret;
153 150
 
154 151
     return 0;
155 152
 }
... ...
@@ -126,28 +126,25 @@ static int query_formats(AVFilterContext *ctx)
126 126
     AVFilterLink *outlink = ctx->outputs[0];
127 127
     static const enum AVSampleFormat sample_fmts[] = { AV_SAMPLE_FMT_S16P, AV_SAMPLE_FMT_NONE };
128 128
     static const enum AVPixelFormat pix_fmts[] = { AV_PIX_FMT_YUVJ444P, AV_PIX_FMT_NONE };
129
+    int ret;
129 130
 
130 131
     /* set input audio formats */
131 132
     formats = ff_make_format_list(sample_fmts);
132
-    if (!formats)
133
-        return AVERROR(ENOMEM);
134
-    ff_formats_ref(formats, &inlink->out_formats);
133
+    if ((ret = ff_formats_ref(formats, &inlink->out_formats)) < 0)
134
+        return ret;
135 135
 
136 136
     layouts = ff_all_channel_layouts();
137
-    if (!layouts)
138
-        return AVERROR(ENOMEM);
139
-    ff_channel_layouts_ref(layouts, &inlink->out_channel_layouts);
137
+    if ((ret = ff_channel_layouts_ref(layouts, &inlink->out_channel_layouts)) < 0)
138
+        return ret;
140 139
 
141 140
     formats = ff_all_samplerates();
142
-    if (!formats)
143
-        return AVERROR(ENOMEM);
144
-    ff_formats_ref(formats, &inlink->out_samplerates);
141
+    if ((ret = ff_formats_ref(formats, &inlink->out_samplerates)) < 0)
142
+        return ret;
145 143
 
146 144
     /* set output video format */
147 145
     formats = ff_make_format_list(pix_fmts);
148
-    if (!formats)
149
-        return AVERROR(ENOMEM);
150
-    ff_formats_ref(formats, &outlink->in_formats);
146
+    if ((ret = ff_formats_ref(formats, &outlink->in_formats)) < 0)
147
+        return ret;
151 148
 
152 149
     return 0;
153 150
 }
... ...
@@ -85,26 +85,23 @@ static int query_formats(AVFilterContext *ctx)
85 85
     AVFilterLink *outlink = ctx->outputs[0];
86 86
     static const enum AVSampleFormat sample_fmts[] = { AV_SAMPLE_FMT_FLTP, AV_SAMPLE_FMT_NONE };
87 87
     static const enum AVPixelFormat pix_fmts[] = { AV_PIX_FMT_RGBA, AV_PIX_FMT_NONE };
88
+    int ret;
88 89
 
89 90
     formats = ff_make_format_list(sample_fmts);
90
-    if (!formats)
91
-        return AVERROR(ENOMEM);
92
-    ff_formats_ref(formats, &inlink->out_formats);
91
+    if ((ret = ff_formats_ref(formats, &inlink->out_formats)) < 0)
92
+        return ret;
93 93
 
94 94
     layouts = ff_all_channel_layouts();
95
-    if (!layouts)
96
-        return AVERROR(ENOMEM);
97
-    ff_channel_layouts_ref(layouts, &inlink->out_channel_layouts);
95
+    if ((ret = ff_channel_layouts_ref(layouts, &inlink->out_channel_layouts)) < 0)
96
+        return ret;
98 97
 
99 98
     formats = ff_all_samplerates();
100
-    if (!formats)
101
-        return AVERROR(ENOMEM);
102
-    ff_formats_ref(formats, &inlink->out_samplerates);
99
+    if ((ret = ff_formats_ref(formats, &inlink->out_samplerates)) < 0)
100
+        return ret;
103 101
 
104 102
     formats = ff_make_format_list(pix_fmts);
105
-    if (!formats)
106
-        return AVERROR(ENOMEM);
107
-    ff_formats_ref(formats, &outlink->in_formats);
103
+    if ((ret = ff_formats_ref(formats, &outlink->in_formats)) < 0)
104
+        return ret;
108 105
 
109 106
     return 0;
110 107
 }
... ...
@@ -117,28 +117,25 @@ static int query_formats(AVFilterContext *ctx)
117 117
     AVFilterLink *outlink = ctx->outputs[0];
118 118
     static const enum AVSampleFormat sample_fmts[] = { AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_NONE };
119 119
     static const enum AVPixelFormat pix_fmts[] = { AV_PIX_FMT_GRAY8, AV_PIX_FMT_NONE };
120
+    int ret;
120 121
 
121 122
     /* set input audio formats */
122 123
     formats = ff_make_format_list(sample_fmts);
123
-    if (!formats)
124
-        return AVERROR(ENOMEM);
125
-    ff_formats_ref(formats, &inlink->out_formats);
124
+    if ((ret = ff_formats_ref(formats, &inlink->out_formats)) < 0)
125
+        return ret;
126 126
 
127 127
     layouts = ff_all_channel_layouts();
128
-    if (!layouts)
129
-        return AVERROR(ENOMEM);
130
-    ff_channel_layouts_ref(layouts, &inlink->out_channel_layouts);
128
+    if ((ret = ff_channel_layouts_ref(layouts, &inlink->out_channel_layouts)) < 0)
129
+        return ret;
131 130
 
132 131
     formats = ff_all_samplerates();
133
-    if (!formats)
134
-        return AVERROR(ENOMEM);
135
-    ff_formats_ref(formats, &inlink->out_samplerates);
132
+    if ((ret = ff_formats_ref(formats, &inlink->out_samplerates)) < 0)
133
+        return ret;
136 134
 
137 135
     /* set output video format */
138 136
     formats = ff_make_format_list(pix_fmts);
139
-    if (!formats)
140
-        return AVERROR(ENOMEM);
141
-    ff_formats_ref(formats, &outlink->in_formats);
137
+    if ((ret = ff_formats_ref(formats, &outlink->in_formats)) < 0)
138
+        return ret;
142 139
 
143 140
     return 0;
144 141
 }
... ...
@@ -317,18 +317,15 @@ static int filter_query_formats(AVFilterContext *ctx)
317 317
         sanitize_channel_layouts(ctx, ctx->outputs[i]->in_channel_layouts);
318 318
 
319 319
     formats = ff_all_formats(type);
320
-    if (!formats)
321
-        return AVERROR(ENOMEM);
322
-    ff_set_common_formats(ctx, formats);
320
+    if ((ret = ff_set_common_formats(ctx, formats)) < 0)
321
+        return ret;
323 322
     if (type == AVMEDIA_TYPE_AUDIO) {
324 323
         samplerates = ff_all_samplerates();
325
-        if (!samplerates)
326
-            return AVERROR(ENOMEM);
327
-        ff_set_common_samplerates(ctx, samplerates);
324
+        if ((ret = ff_set_common_samplerates(ctx, samplerates)) < 0)
325
+            return ret;
328 326
         chlayouts = ff_all_channel_layouts();
329
-        if (!chlayouts)
330
-            return AVERROR(ENOMEM);
331
-        ff_set_common_channel_layouts(ctx, chlayouts);
327
+        if ((ret = ff_set_common_channel_layouts(ctx, chlayouts)) < 0)
328
+            return ret;
332 329
     }
333 330
     return 0;
334 331
 }
... ...
@@ -728,7 +725,7 @@ static int pick_format(AVFilterLink *link, AVFilterLink *ref)
728 728
     return 0;
729 729
 }
730 730
 
731
-#define REDUCE_FORMATS(fmt_type, list_type, list, var, nb, add_format) \
731
+#define REDUCE_FORMATS(fmt_type, list_type, list, var, nb, add_format, unref_format) \
732 732
 do {                                                                   \
733 733
     for (i = 0; i < filter->nb_inputs; i++) {                          \
734 734
         AVFilterLink *link = filter->inputs[i];                        \
... ...
@@ -769,9 +766,9 @@ static int reduce_formats_on_filter(AVFilterContext *filter)
769 769
     int i, j, k, ret = 0;
770 770
 
771 771
     REDUCE_FORMATS(int,      AVFilterFormats,        formats,         formats,
772
-                   nb_formats, ff_add_format);
772
+                   nb_formats, ff_add_format, ff_formats_unref);
773 773
     REDUCE_FORMATS(int,      AVFilterFormats,        samplerates,     formats,
774
-                   nb_formats, ff_add_format);
774
+                   nb_formats, ff_add_format, ff_formats_unref);
775 775
 
776 776
     /* reduce channel layouts */
777 777
     for (i = 0; i < filter->nb_inputs; i++) {
... ...
@@ -795,7 +792,8 @@ static int reduce_formats_on_filter(AVFilterContext *filter)
795 795
                 (!FF_LAYOUT2COUNT(fmt) || fmts->all_counts)) {
796 796
                 /* Turn the infinite list into a singleton */
797 797
                 fmts->all_layouts = fmts->all_counts  = 0;
798
-                ff_add_channel_layout(&outlink->in_channel_layouts, fmt);
798
+                if (ff_add_channel_layout(&outlink->in_channel_layouts, fmt) < 0)
799
+                    ret = 1;
799 800
                 break;
800 801
             }
801 802
 
... ...
@@ -302,13 +302,13 @@ static int vsink_query_formats(AVFilterContext *ctx)
302 302
     CHECK_LIST_SIZE(pixel_fmts)
303 303
     if (buf->pixel_fmts_size) {
304 304
         for (i = 0; i < NB_ITEMS(buf->pixel_fmts); i++)
305
-            if ((ret = ff_add_format(&formats, buf->pixel_fmts[i])) < 0) {
306
-                ff_formats_unref(&formats);
305
+            if ((ret = ff_add_format(&formats, buf->pixel_fmts[i])) < 0)
307 306
                 return ret;
308
-            }
309
-        ff_set_common_formats(ctx, formats);
307
+        if ((ret = ff_set_common_formats(ctx, formats)) < 0)
308
+            return ret;
310 309
     } else {
311
-        ff_default_query_formats(ctx);
310
+        if ((ret = ff_default_query_formats(ctx)) < 0)
311
+            return ret;
312 312
     }
313 313
 
314 314
     return 0;
... ...
@@ -346,25 +346,20 @@ static int asink_query_formats(AVFilterContext *ctx)
346 346
 
347 347
     if (buf->sample_fmts_size) {
348 348
         for (i = 0; i < NB_ITEMS(buf->sample_fmts); i++)
349
-            if ((ret = ff_add_format(&formats, buf->sample_fmts[i])) < 0) {
350
-                ff_formats_unref(&formats);
349
+            if ((ret = ff_add_format(&formats, buf->sample_fmts[i])) < 0)
351 350
                 return ret;
352
-            }
353
-        ff_set_common_formats(ctx, formats);
351
+        if ((ret = ff_set_common_formats(ctx, formats)) < 0)
352
+            return ret;
354 353
     }
355 354
 
356 355
     if (buf->channel_layouts_size || buf->channel_counts_size ||
357 356
         buf->all_channel_counts) {
358 357
         for (i = 0; i < NB_ITEMS(buf->channel_layouts); i++)
359
-            if ((ret = ff_add_channel_layout(&layouts, buf->channel_layouts[i])) < 0) {
360
-                ff_channel_layouts_unref(&layouts);
358
+            if ((ret = ff_add_channel_layout(&layouts, buf->channel_layouts[i])) < 0)
361 359
                 return ret;
362
-            }
363 360
         for (i = 0; i < NB_ITEMS(buf->channel_counts); i++)
364
-            if ((ret = ff_add_channel_layout(&layouts, FF_COUNT2LAYOUT(buf->channel_counts[i]))) < 0) {
365
-                ff_channel_layouts_unref(&layouts);
361
+            if ((ret = ff_add_channel_layout(&layouts, FF_COUNT2LAYOUT(buf->channel_counts[i]))) < 0)
366 362
                 return ret;
367
-            }
368 363
         if (buf->all_channel_counts) {
369 364
             if (layouts)
370 365
                 av_log(ctx, AV_LOG_WARNING,
... ...
@@ -372,17 +367,17 @@ static int asink_query_formats(AVFilterContext *ctx)
372 372
             else if (!(layouts = ff_all_channel_counts()))
373 373
                 return AVERROR(ENOMEM);
374 374
         }
375
-        ff_set_common_channel_layouts(ctx, layouts);
375
+        if ((ret = ff_set_common_channel_layouts(ctx, layouts)) < 0)
376
+            return ret;
376 377
     }
377 378
 
378 379
     if (buf->sample_rates_size) {
379 380
         formats = NULL;
380 381
         for (i = 0; i < NB_ITEMS(buf->sample_rates); i++)
381
-            if ((ret = ff_add_format(&formats, buf->sample_rates[i])) < 0) {
382
-                ff_formats_unref(&formats);
382
+            if ((ret = ff_add_format(&formats, buf->sample_rates[i])) < 0)
383 383
                 return ret;
384
-            }
385
-        ff_set_common_samplerates(ctx, formats);
384
+        if ((ret = ff_set_common_samplerates(ctx, formats)) < 0)
385
+            return ret;
386 386
     }
387 387
 
388 388
     return 0;
... ...
@@ -314,23 +314,27 @@ static int query_formats(AVFilterContext *ctx)
314 314
     AVFilterChannelLayouts *channel_layouts = NULL;
315 315
     AVFilterFormats *formats = NULL;
316 316
     AVFilterFormats *samplerates = NULL;
317
+    int ret;
317 318
 
318 319
     switch (ctx->outputs[0]->type) {
319 320
     case AVMEDIA_TYPE_VIDEO:
320
-        ff_add_format(&formats, c->pix_fmt);
321
-        ff_set_common_formats(ctx, formats);
321
+        if ((ret = ff_add_format         (&formats, c->pix_fmt)) < 0 ||
322
+            (ret = ff_set_common_formats (ctx     , formats   )) < 0)
323
+            return ret;
322 324
         break;
323 325
     case AVMEDIA_TYPE_AUDIO:
324
-        ff_add_format(&formats,           c->sample_fmt);
325
-        ff_set_common_formats(ctx, formats);
326
-
327
-        ff_add_format(&samplerates,       c->sample_rate);
328
-        ff_set_common_samplerates(ctx, samplerates);
326
+        if ((ret = ff_add_format             (&formats    , c->sample_fmt )) < 0 ||
327
+            (ret = ff_set_common_formats     (ctx         , formats       )) < 0 ||
328
+            (ret = ff_add_format             (&samplerates, c->sample_rate)) < 0 ||
329
+            (ret = ff_set_common_samplerates (ctx         , samplerates   )) < 0)
330
+            return ret;
329 331
 
330
-        ff_add_channel_layout(&channel_layouts,
332
+        if ((ret = ff_add_channel_layout(&channel_layouts,
331 333
                               c->channel_layout ? c->channel_layout :
332
-                              FF_COUNT2LAYOUT(c->channels));
333
-        ff_set_common_channel_layouts(ctx, channel_layouts);
334
+                              FF_COUNT2LAYOUT(c->channels))) < 0)
335
+            return ret;
336
+        if ((ret = ff_set_common_channel_layouts(ctx, channel_layouts)) < 0)
337
+            return ret;
334 338
         break;
335 339
     default:
336 340
         return AVERROR(EINVAL);
... ...
@@ -532,10 +532,12 @@ AVFilterFormats *ff_draw_supported_pixel_formats(unsigned flags)
532 532
     enum AVPixelFormat i;
533 533
     FFDrawContext draw;
534 534
     AVFilterFormats *fmts = NULL;
535
+    int ret;
535 536
 
536 537
     for (i = 0; av_pix_fmt_desc_get(i); i++)
537
-        if (ff_draw_init(&draw, i, flags) >= 0)
538
-            ff_add_format(&fmts, i);
538
+        if (ff_draw_init(&draw, i, flags) >= 0 &&
539
+            (ret = ff_add_format(&fmts, i)) < 0)
540
+            return NULL;
539 541
     return fmts;
540 542
 }
541 543
 
... ...
@@ -110,11 +110,11 @@ static int query_formats(AVFilterContext *ctx)
110 110
         AV_PIX_FMT_RGBA,
111 111
         AV_PIX_FMT_NONE
112 112
     };
113
+    int ret;
113 114
 
114 115
     AVFilterFormats *fmts_list = ff_make_format_list(pix_fmts);
115
-    if (!fmts_list)
116
-        return AVERROR(ENOMEM);
117
-    ff_formats_ref(fmts_list, &outlink->in_formats);
116
+    if ((ret = ff_formats_ref(fmts_list, &outlink->in_formats)) < 0)
117
+        return ret;
118 118
 
119 119
     return 0;
120 120
 }
... ...
@@ -826,6 +826,7 @@ static int query_formats(AVFilterContext *ctx)
826 826
     AVFilterChannelLayouts *layouts;
827 827
     AVFilterLink *inlink = ctx->inputs[0];
828 828
     AVFilterLink *outlink = ctx->outputs[0];
829
+    int ret;
829 830
 
830 831
     static const enum AVSampleFormat sample_fmts[] = { AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_NONE };
831 832
     static const int input_srate[] = {48000, -1}; // ITU-R BS.1770 provides coeff only for 48kHz
... ...
@@ -834,9 +835,8 @@ static int query_formats(AVFilterContext *ctx)
834 834
     /* set optional output video format */
835 835
     if (ebur128->do_video) {
836 836
         formats = ff_make_format_list(pix_fmts);
837
-        if (!formats)
838
-            return AVERROR(ENOMEM);
839
-        ff_formats_ref(formats, &outlink->in_formats);
837
+        if ((ret = ff_formats_ref(formats, &outlink->in_formats)) < 0)
838
+            return ret;
840 839
         outlink = ctx->outputs[1];
841 840
     }
842 841
 
... ...
@@ -844,22 +844,19 @@ static int query_formats(AVFilterContext *ctx)
844 844
      * Note: ff_set_common_* functions are not used because they affect all the
845 845
      * links, and thus break the video format negotiation */
846 846
     formats = ff_make_format_list(sample_fmts);
847
-    if (!formats)
848
-        return AVERROR(ENOMEM);
849
-    ff_formats_ref(formats, &inlink->out_formats);
850
-    ff_formats_ref(formats, &outlink->in_formats);
847
+    if ((ret = ff_formats_ref(formats, &inlink->out_formats)) < 0 ||
848
+        (ret = ff_formats_ref(formats, &outlink->in_formats)) < 0)
849
+        return ret;
851 850
 
852 851
     layouts = ff_all_channel_layouts();
853
-    if (!layouts)
854
-        return AVERROR(ENOMEM);
855
-    ff_channel_layouts_ref(layouts, &inlink->out_channel_layouts);
856
-    ff_channel_layouts_ref(layouts, &outlink->in_channel_layouts);
852
+    if ((ret = ff_channel_layouts_ref(layouts, &inlink->out_channel_layouts)) < 0 ||
853
+        (ret = ff_channel_layouts_ref(layouts, &outlink->in_channel_layouts)) < 0)
854
+        return ret;
857 855
 
858 856
     formats = ff_make_format_list(input_srate);
859
-    if (!formats)
860
-        return AVERROR(ENOMEM);
861
-    ff_formats_ref(formats, &inlink->out_samplerates);
862
-    ff_formats_ref(formats, &outlink->in_samplerates);
857
+    if ((ret = ff_formats_ref(formats, &inlink->out_samplerates)) < 0 ||
858
+        (ret = ff_formats_ref(formats, &outlink->in_samplerates)) < 0)
859
+        return ret;
863 860
 
864 861
     return 0;
865 862
 }
... ...
@@ -300,17 +300,20 @@ AVFilterChannelLayouts *avfilter_make_format64_list(const int64_t *fmts)
300 300
     return formats;
301 301
 }
302 302
 
303
-#define ADD_FORMAT(f, fmt, type, list, nb)                  \
303
+#define ADD_FORMAT(f, fmt, unref_fn, type, list, nb)        \
304 304
 do {                                                        \
305 305
     type *fmts;                                             \
306 306
     void *oldf = *f;                                        \
307 307
                                                             \
308
-    if (!(*f) && !(*f = av_mallocz(sizeof(**f))))           \
308
+    if (!(*f) && !(*f = av_mallocz(sizeof(**f)))) {         \
309
+        unref_fn(f);                                        \
309 310
         return AVERROR(ENOMEM);                             \
311
+    }                                                       \
310 312
                                                             \
311 313
     fmts = av_realloc_array((*f)->list, (*f)->nb + 1,       \
312 314
                             sizeof(*(*f)->list));           \
313 315
     if (!fmts) {                                            \
316
+        unref_fn(f);                                        \
314 317
         if (!oldf)                                          \
315 318
             av_freep(f);                                    \
316 319
         return AVERROR(ENOMEM);                             \
... ...
@@ -322,14 +325,14 @@ do {                                                        \
322 322
 
323 323
 int ff_add_format(AVFilterFormats **avff, int64_t fmt)
324 324
 {
325
-    ADD_FORMAT(avff, fmt, int, formats, nb_formats);
325
+    ADD_FORMAT(avff, fmt, ff_formats_unref, int, formats, nb_formats);
326 326
     return 0;
327 327
 }
328 328
 
329 329
 int ff_add_channel_layout(AVFilterChannelLayouts **l, uint64_t channel_layout)
330 330
 {
331 331
     av_assert1(!(*l && (*l)->all_layouts));
332
-    ADD_FORMAT(l, channel_layout, uint64_t, channel_layouts, nb_channel_layouts);
332
+    ADD_FORMAT(l, channel_layout, ff_channel_layouts_unref, uint64_t, channel_layouts, nb_channel_layouts);
333 333
     return 0;
334 334
 }
335 335
 
... ...
@@ -340,12 +343,14 @@ AVFilterFormats *ff_all_formats(enum AVMediaType type)
340 340
     if (type == AVMEDIA_TYPE_VIDEO) {
341 341
         const AVPixFmtDescriptor *desc = NULL;
342 342
         while ((desc = av_pix_fmt_desc_next(desc))) {
343
-            ff_add_format(&ret, av_pix_fmt_desc_get_id(desc));
343
+            if (ff_add_format(&ret, av_pix_fmt_desc_get_id(desc)) < 0)
344
+                return NULL;
344 345
         }
345 346
     } else if (type == AVMEDIA_TYPE_AUDIO) {
346 347
         enum AVSampleFormat fmt = 0;
347 348
         while (av_get_sample_fmt_name(fmt)) {
348
-            ff_add_format(&ret, fmt);
349
+            if (ff_add_format(&ret, fmt) < 0)
350
+                return NULL;
349 351
             fmt++;
350 352
         }
351 353
     }
... ...
@@ -370,7 +375,8 @@ AVFilterFormats *ff_planar_sample_fmts(void)
370 370
 
371 371
     for (fmt = 0; av_get_bytes_per_sample(fmt)>0; fmt++)
372 372
         if (av_sample_fmt_is_planar(fmt))
373
-            ff_add_format(&ret, fmt);
373
+            if (ff_add_format(&ret, fmt) < 0)
374
+                return NULL;
374 375
 
375 376
     return ret;
376 377
 }
... ...
@@ -399,15 +405,17 @@ AVFilterChannelLayouts *ff_all_channel_counts(void)
399 399
     return ret;
400 400
 }
401 401
 
402
-#define FORMATS_REF(f, ref)                                                     \
402
+#define FORMATS_REF(f, ref, unref_fn)                                           \
403 403
     void *tmp;                                                                  \
404 404
                                                                                 \
405
-    if (!ref)                                                                   \
406
-        return AVERROR_BUG;                                                     \
405
+    if (!f || !ref)                                                             \
406
+        return AVERROR(ENOMEM);                                                 \
407 407
                                                                                 \
408 408
     tmp = av_realloc_array(f->refs, sizeof(*f->refs), f->refcount + 1);         \
409
-    if (!tmp)                                                                   \
409
+    if (!tmp) {                                                                 \
410
+        unref_fn(&f);                                                           \
410 411
         return AVERROR(ENOMEM);                                                 \
412
+    }                                                                           \
411 413
     f->refs = tmp;                                                              \
412 414
     f->refs[f->refcount++] = ref;                                               \
413 415
     *ref = f;                                                                   \
... ...
@@ -415,12 +423,12 @@ AVFilterChannelLayouts *ff_all_channel_counts(void)
415 415
 
416 416
 int ff_channel_layouts_ref(AVFilterChannelLayouts *f, AVFilterChannelLayouts **ref)
417 417
 {
418
-    FORMATS_REF(f, ref);
418
+    FORMATS_REF(f, ref, ff_channel_layouts_unref);
419 419
 }
420 420
 
421 421
 int ff_formats_ref(AVFilterFormats *f, AVFilterFormats **ref)
422 422
 {
423
-    FORMATS_REF(f, ref);
423
+    FORMATS_REF(f, ref, ff_formats_unref);
424 424
 }
425 425
 
426 426
 #define FIND_REF_INDEX(ref, idx)            \
... ...
@@ -488,25 +496,29 @@ void ff_formats_changeref(AVFilterFormats **oldref, AVFilterFormats **newref)
488 488
     FORMATS_CHANGEREF(oldref, newref);
489 489
 }
490 490
 
491
-#define SET_COMMON_FORMATS(ctx, fmts, in_fmts, out_fmts, ref, list) \
491
+#define SET_COMMON_FORMATS(ctx, fmts, in_fmts, out_fmts, ref_fn, unref_fn, list) \
492 492
     int count = 0, i;                                               \
493 493
                                                                     \
494 494
     if (!fmts)                                                      \
495
-        return AVERROR_BUG;                                         \
495
+        return AVERROR(ENOMEM);                                     \
496 496
                                                                     \
497 497
     for (i = 0; i < ctx->nb_inputs; i++) {                          \
498 498
         if (ctx->inputs[i] && !ctx->inputs[i]->out_fmts) {          \
499
-            int ret = ref(fmts, &ctx->inputs[i]->out_fmts);         \
500
-            if (ret < 0)                                            \
499
+            int ret = ref_fn(fmts, &ctx->inputs[i]->out_fmts);      \
500
+            if (ret < 0) {                                          \
501
+                unref_fn(&fmts);                                    \
501 502
                 return ret;                                         \
503
+            }                                                       \
502 504
             count++;                                                \
503 505
         }                                                           \
504 506
     }                                                               \
505 507
     for (i = 0; i < ctx->nb_outputs; i++) {                         \
506 508
         if (ctx->outputs[i] && !ctx->outputs[i]->in_fmts) {         \
507
-            int ret = ref(fmts, &ctx->outputs[i]->in_fmts);         \
508
-            if (ret < 0)                                            \
509
+            int ret = ref_fn(fmts, &ctx->outputs[i]->in_fmts);      \
510
+            if (ret < 0) {                                          \
511
+                unref_fn(&fmts);                                    \
509 512
                 return ret;                                         \
513
+            }                                                       \
510 514
             count++;                                                \
511 515
         }                                                           \
512 516
     }                                                               \
... ...
@@ -523,14 +535,14 @@ int ff_set_common_channel_layouts(AVFilterContext *ctx,
523 523
                                   AVFilterChannelLayouts *layouts)
524 524
 {
525 525
     SET_COMMON_FORMATS(ctx, layouts, in_channel_layouts, out_channel_layouts,
526
-                       ff_channel_layouts_ref, channel_layouts);
526
+                       ff_channel_layouts_ref, ff_channel_layouts_unref, channel_layouts);
527 527
 }
528 528
 
529 529
 int ff_set_common_samplerates(AVFilterContext *ctx,
530 530
                               AVFilterFormats *samplerates)
531 531
 {
532 532
     SET_COMMON_FORMATS(ctx, samplerates, in_samplerates, out_samplerates,
533
-                       ff_formats_ref, formats);
533
+                       ff_formats_ref, ff_formats_unref, formats);
534 534
 }
535 535
 
536 536
 /**
... ...
@@ -541,7 +553,7 @@ int ff_set_common_samplerates(AVFilterContext *ctx,
541 541
 int ff_set_common_formats(AVFilterContext *ctx, AVFilterFormats *formats)
542 542
 {
543 543
     SET_COMMON_FORMATS(ctx, formats, in_formats, out_formats,
544
-                       ff_formats_ref, formats);
544
+                       ff_formats_ref, ff_formats_unref, formats);
545 545
 }
546 546
 
547 547
 static int default_query_formats_common(AVFilterContext *ctx,
... ...
@@ -333,7 +333,7 @@ static int movie_query_formats(AVFilterContext *ctx)
333 333
     MovieContext *movie = ctx->priv;
334 334
     int list[] = { 0, -1 };
335 335
     int64_t list64[] = { 0, -1 };
336
-    int i;
336
+    int i, ret;
337 337
 
338 338
     for (i = 0; i < ctx->nb_outputs; i++) {
339 339
         MovieStream *st = &movie->st[i];
... ...
@@ -343,16 +343,20 @@ static int movie_query_formats(AVFilterContext *ctx)
343 343
         switch (c->codec_type) {
344 344
         case AVMEDIA_TYPE_VIDEO:
345 345
             list[0] = c->pix_fmt;
346
-            ff_formats_ref(ff_make_format_list(list), &outlink->in_formats);
346
+            if ((ret = ff_formats_ref(ff_make_format_list(list), &outlink->in_formats)) < 0)
347
+                return ret;
347 348
             break;
348 349
         case AVMEDIA_TYPE_AUDIO:
349 350
             list[0] = c->sample_fmt;
350
-            ff_formats_ref(ff_make_format_list(list), &outlink->in_formats);
351
+            if ((ret = ff_formats_ref(ff_make_format_list(list), &outlink->in_formats)) < 0)
352
+                return ret;
351 353
             list[0] = c->sample_rate;
352
-            ff_formats_ref(ff_make_format_list(list), &outlink->in_samplerates);
354
+            if ((ret = ff_formats_ref(ff_make_format_list(list), &outlink->in_samplerates)) < 0)
355
+                return ret;
353 356
             list64[0] = c->channel_layout;
354
-            ff_channel_layouts_ref(avfilter_make_format64_list(list64),
355
-                                   &outlink->in_channel_layouts);
357
+            if ((ret = ff_channel_layouts_ref(avfilter_make_format64_list(list64),
358
+                                   &outlink->in_channel_layouts)) < 0)
359
+                return ret;
356 360
             break;
357 361
         }
358 362
     }
... ...
@@ -57,11 +57,16 @@ static int query_formats(AVFilterContext *ctx)
57 57
         AV_PIX_FMT_NONE
58 58
     };
59 59
     static const enum AVPixelFormat alpha_fmts[] = { AV_PIX_FMT_GRAY8, AV_PIX_FMT_NONE };
60
-    AVFilterFormats *main_formats = ff_make_format_list(main_fmts);
61
-    AVFilterFormats *alpha_formats = ff_make_format_list(alpha_fmts);
62
-    ff_formats_ref(main_formats, &ctx->inputs[0]->out_formats);
63
-    ff_formats_ref(alpha_formats, &ctx->inputs[1]->out_formats);
64
-    ff_formats_ref(main_formats, &ctx->outputs[0]->in_formats);
60
+    AVFilterFormats *main_formats, *alpha_formats;
61
+    int ret;
62
+
63
+    if (!(main_formats = ff_make_format_list(main_fmts)) ||
64
+        !(alpha_formats = ff_make_format_list(alpha_fmts)))
65
+        return AVERROR(ENOMEM);
66
+    if ((ret = ff_formats_ref(main_formats , &ctx->inputs[0]->out_formats)) < 0 ||
67
+        (ret = ff_formats_ref(alpha_formats, &ctx->inputs[1]->out_formats)) < 0 ||
68
+        (ret = ff_formats_ref(main_formats , &ctx->outputs[0]->in_formats)) < 0)
69
+        return ret;
65 70
     return 0;
66 71
 }
67 72
 
... ...
@@ -118,14 +118,15 @@ static av_cold void uninit(AVFilterContext *ctx)
118 118
 static int query_formats(AVFilterContext *ctx)
119 119
 {
120 120
     AVFilterFormats *formats = NULL;
121
-    int fmt;
121
+    int fmt, ret;
122 122
 
123 123
     for (fmt = 0; av_pix_fmt_desc_get(fmt); fmt++) {
124 124
         const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(fmt);
125 125
         if (!(desc->flags & (AV_PIX_FMT_FLAG_HWACCEL | AV_PIX_FMT_FLAG_BITSTREAM | AV_PIX_FMT_FLAG_PAL)) &&
126 126
             (desc->flags & AV_PIX_FMT_FLAG_PLANAR || desc->nb_components == 1) &&
127
-            (!(desc->flags & AV_PIX_FMT_FLAG_BE) == !HAVE_BIGENDIAN || desc->comp[0].depth == 8))
128
-            ff_add_format(&formats, fmt);
127
+            (!(desc->flags & AV_PIX_FMT_FLAG_BE) == !HAVE_BIGENDIAN || desc->comp[0].depth == 8) &&
128
+            (ret = ff_add_format(&formats, fmt)) < 0)
129
+            return ret;
129 130
     }
130 131
 
131 132
     return ff_set_common_formats(ctx, formats);
... ...
@@ -93,13 +93,14 @@ typedef struct CropContext {
93 93
 static int query_formats(AVFilterContext *ctx)
94 94
 {
95 95
     AVFilterFormats *formats = NULL;
96
-    int fmt;
96
+    int fmt, ret;
97 97
 
98 98
     for (fmt = 0; av_pix_fmt_desc_get(fmt); fmt++) {
99 99
         const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(fmt);
100 100
         if (!(desc->flags & (AV_PIX_FMT_FLAG_HWACCEL | AV_PIX_FMT_FLAG_BITSTREAM)) &&
101
-            !((desc->log2_chroma_w || desc->log2_chroma_h) && !(desc->flags & AV_PIX_FMT_FLAG_PLANAR)))
102
-            ff_add_format(&formats, fmt);
101
+            !((desc->log2_chroma_w || desc->log2_chroma_h) && !(desc->flags & AV_PIX_FMT_FLAG_PLANAR)) &&
102
+            (ret = ff_add_format(&formats, fmt)) < 0)
103
+            return ret;
103 104
     }
104 105
 
105 106
     return ff_set_common_formats(ctx, formats);
... ...
@@ -116,14 +116,15 @@ static av_cold int init(AVFilterContext *ctx)
116 116
 static int query_formats(AVFilterContext *ctx)
117 117
 {
118 118
     AVFilterFormats *pix_fmts = NULL;
119
-    int fmt;
119
+    int fmt, ret;
120 120
 
121 121
     for (fmt = 0; av_pix_fmt_desc_get(fmt); fmt++) {
122 122
         const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(fmt);
123 123
         if (!(desc->flags & AV_PIX_FMT_FLAG_HWACCEL ||
124 124
               desc->flags & AV_PIX_FMT_FLAG_PAL     ||
125
-              desc->flags & AV_PIX_FMT_FLAG_BITSTREAM))
126
-            ff_add_format(&pix_fmts, fmt);
125
+              desc->flags & AV_PIX_FMT_FLAG_BITSTREAM) &&
126
+             (ret = ff_add_format(&pix_fmts, fmt)) < 0)
127
+            return ret;
127 128
     }
128 129
 
129 130
     return ff_set_common_formats(ctx, pix_fmts);
... ...
@@ -76,8 +76,7 @@ static int query_formats(AVFilterContext *ctx)
76 76
         AV_PIX_FMT_GRAY8, AV_PIX_FMT_NONE
77 77
     };
78 78
 
79
-    ff_set_common_formats(ctx, ff_make_format_list(pix_fmts));
80
-    return 0;
79
+    return ff_set_common_formats(ctx, ff_make_format_list(pix_fmts));
81 80
 }
82 81
 
83 82
 static void displace_planar(DisplaceContext *s, const AVFrame *in,
... ...
@@ -83,6 +83,7 @@ static av_cold int init(AVFilterContext *ctx)
83 83
 static int query_formats(AVFilterContext *ctx)
84 84
 {
85 85
     ELBGContext *elbg = ctx->priv;
86
+    int ret;
86 87
 
87 88
     static const enum AVPixelFormat pix_fmts[] = {
88 89
         AV_PIX_FMT_ARGB, AV_PIX_FMT_RGBA, AV_PIX_FMT_ABGR, AV_PIX_FMT_BGRA,
... ...
@@ -99,8 +100,9 @@ static int query_formats(AVFilterContext *ctx)
99 99
             AV_PIX_FMT_PAL8,
100 100
             AV_PIX_FMT_NONE
101 101
         };
102
-        ff_formats_ref(ff_make_format_list(pix_fmts), &ctx->inputs[0]->out_formats);
103
-        ff_formats_ref(ff_make_format_list(pal8_fmt), &ctx->outputs[0]->in_formats);
102
+        if ((ret = ff_formats_ref(ff_make_format_list(pix_fmts), &ctx->inputs[0]->out_formats)) < 0 ||
103
+            (ret = ff_formats_ref(ff_make_format_list(pal8_fmt), &ctx->outputs[0]->in_formats)) < 0)
104
+            return ret;
104 105
     }
105 106
     return 0;
106 107
 }
... ...
@@ -99,7 +99,7 @@ static int query_formats(AVFilterContext *ctx)
99 99
     const enum AVPixelFormat *out_pixfmts;
100 100
     const AVPixFmtDescriptor *desc;
101 101
     AVFilterFormats *avff;
102
-    int i, depth = 0, be = 0;
102
+    int i, ret, depth = 0, be = 0;
103 103
 
104 104
     if (!ctx->inputs[0]->in_formats ||
105 105
         !ctx->inputs[0]->in_formats->nb_formats) {
... ...
@@ -107,7 +107,8 @@ static int query_formats(AVFilterContext *ctx)
107 107
     }
108 108
 
109 109
     if (!ctx->inputs[0]->out_formats)
110
-        ff_formats_ref(ff_make_format_list(in_pixfmts), &ctx->inputs[0]->out_formats);
110
+        if ((ret = ff_formats_ref(ff_make_format_list(in_pixfmts), &ctx->inputs[0]->out_formats)) < 0)
111
+            return ret;
111 112
 
112 113
     avff = ctx->inputs[0]->in_formats;
113 114
     desc = av_pix_fmt_desc_get(avff->formats[0]);
... ...
@@ -129,7 +130,8 @@ static int query_formats(AVFilterContext *ctx)
129 129
         out_pixfmts = out16le_pixfmts;
130 130
 
131 131
     for (i = 0; i < ctx->nb_outputs; i++)
132
-        ff_formats_ref(ff_make_format_list(out_pixfmts), &ctx->outputs[i]->in_formats);
132
+        if ((ret = ff_formats_ref(ff_make_format_list(out_pixfmts), &ctx->outputs[i]->in_formats)) < 0)
133
+            return ret;
133 134
     return 0;
134 135
 }
135 136
 
... ...
@@ -55,13 +55,12 @@ static int query_formats(AVFilterContext *ctx)
55 55
                   desc->flags & AV_PIX_FMT_FLAG_PAL     ||
56 56
                   desc->flags & AV_PIX_FMT_FLAG_BITSTREAM) &&
57 57
                 desc->nb_components && !desc->log2_chroma_h &&
58
-                (ret = ff_add_format(&formats, pix_fmt)) < 0) {
59
-                ff_formats_unref(&formats);
58
+                (ret = ff_add_format(&formats, pix_fmt)) < 0)
60 59
                 return ret;
61
-            }
62 60
         }
63
-        ff_formats_ref(formats, &ctx->inputs[0]->out_formats);
64
-        ff_formats_ref(formats, &ctx->outputs[0]->in_formats);
61
+        if ((ret = ff_formats_ref(formats, &ctx->inputs[0]->out_formats)) < 0 ||
62
+            (ret = ff_formats_ref(formats, &ctx->outputs[0]->in_formats)) < 0)
63
+            return ret;
65 64
     }
66 65
 
67 66
     return 0;
... ...
@@ -370,11 +370,14 @@ static int query_formats(AVFilterContext *ctx)
370 370
 {
371 371
     Frei0rContext *s = ctx->priv;
372 372
     AVFilterFormats *formats = NULL;
373
+    int ret;
373 374
 
374 375
     if        (s->plugin_info.color_model == F0R_COLOR_MODEL_BGRA8888) {
375
-        ff_add_format(&formats, AV_PIX_FMT_BGRA);
376
+        if ((ret = ff_add_format(&formats, AV_PIX_FMT_BGRA)) < 0)
377
+            return ret;
376 378
     } else if (s->plugin_info.color_model == F0R_COLOR_MODEL_RGBA8888) {
377
-        ff_add_format(&formats, AV_PIX_FMT_RGBA);
379
+        if ((ret = ff_add_format(&formats, AV_PIX_FMT_RGBA)) < 0)
380
+            return ret;
378 381
     } else {                                   /* F0R_COLOR_MODEL_PACKED32 */
379 382
         static const enum AVPixelFormat pix_fmts[] = {
380 383
             AV_PIX_FMT_BGRA, AV_PIX_FMT_ARGB, AV_PIX_FMT_ABGR, AV_PIX_FMT_ARGB, AV_PIX_FMT_NONE
... ...
@@ -44,15 +44,16 @@ typedef struct FlipContext {
44 44
 static int query_formats(AVFilterContext *ctx)
45 45
 {
46 46
     AVFilterFormats *pix_fmts = NULL;
47
-    int fmt;
47
+    int fmt, ret;
48 48
 
49 49
     for (fmt = 0; av_pix_fmt_desc_get(fmt); fmt++) {
50 50
         const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(fmt);
51 51
         if (!(desc->flags & AV_PIX_FMT_FLAG_HWACCEL ||
52 52
               desc->flags & AV_PIX_FMT_FLAG_BITSTREAM ||
53 53
               (desc->log2_chroma_w != desc->log2_chroma_h &&
54
-               desc->comp[0].plane == desc->comp[1].plane)))
55
-            ff_add_format(&pix_fmts, fmt);
54
+               desc->comp[0].plane == desc->comp[1].plane)) &&
55
+            (ret = ff_add_format(&pix_fmts, fmt)) < 0)
56
+            return ret;
56 57
     }
57 58
 
58 59
     return ff_set_common_formats(ctx, pix_fmts);
... ...
@@ -155,6 +155,7 @@ static int query_formats(AVFilterContext *ctx)
155 155
     HistogramContext *h = ctx->priv;
156 156
     const enum AVPixelFormat *pix_fmts;
157 157
     AVFilterFormats *fmts_list;
158
+    int ret;
158 159
 
159 160
     switch (h->mode) {
160 161
     case MODE_WAVEFORM:
... ...
@@ -173,7 +174,8 @@ static int query_formats(AVFilterContext *ctx)
173 173
         }
174 174
 
175 175
         if (!ctx->inputs[0]->out_formats)
176
-            ff_formats_ref(ff_make_format_list(levels_in_pix_fmts), &ctx->inputs[0]->out_formats);
176
+            if ((ret = ff_formats_ref(ff_make_format_list(levels_in_pix_fmts), &ctx->inputs[0]->out_formats)) < 0)
177
+                return ret;
177 178
         avff = ctx->inputs[0]->in_formats;
178 179
         desc = av_pix_fmt_desc_get(avff->formats[0]);
179 180
         rgb = desc->flags & AV_PIX_FMT_FLAG_RGB;
... ...
@@ -197,7 +199,8 @@ static int query_formats(AVFilterContext *ctx)
197 197
             out_pix_fmts = levels_out_yuv9_pix_fmts;
198 198
         else // if (bits == 10)
199 199
             out_pix_fmts = levels_out_yuv10_pix_fmts;
200
-        ff_formats_ref(ff_make_format_list(out_pix_fmts), &ctx->outputs[0]->in_formats);
200
+        if ((ret = ff_formats_ref(ff_make_format_list(out_pix_fmts), &ctx->outputs[0]->in_formats)) < 0)
201
+            return ret;
201 202
 
202 203
         return 0;
203 204
     }
... ...
@@ -84,12 +84,14 @@ AVFILTER_DEFINE_CLASS(il);
84 84
 static int query_formats(AVFilterContext *ctx)
85 85
 {
86 86
     AVFilterFormats *formats = NULL;
87
-    int fmt;
87
+    int fmt, ret;
88 88
 
89 89
     for (fmt = 0; av_pix_fmt_desc_get(fmt); fmt++) {
90 90
         const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(fmt);
91
-        if (!(desc->flags & AV_PIX_FMT_FLAG_PAL) && !(desc->flags & AV_PIX_FMT_FLAG_HWACCEL))
92
-            ff_add_format(&formats, fmt);
91
+        if (!(desc->flags & AV_PIX_FMT_FLAG_PAL) &&
92
+            !(desc->flags & AV_PIX_FMT_FLAG_HWACCEL) &&
93
+            (ret = ff_add_format(&formats, fmt)) < 0)
94
+            return ret;
93 95
     }
94 96
 
95 97
     return ff_set_common_formats(ctx, formats);
... ...
@@ -58,8 +58,7 @@ static int query_formats(AVFilterContext *ctx)
58 58
         AV_PIX_FMT_NONE
59 59
     };
60 60
 
61
-    ff_set_common_formats(ctx, ff_make_format_list(pix_fmts));
62
-    return 0;
61
+    return ff_set_common_formats(ctx, ff_make_format_list(pix_fmts));
63 62
 }
64 63
 
65 64
 static int process_frame(FFFrameSync *fs)
... ...
@@ -116,22 +116,25 @@ static int query_formats(AVFilterContext *ctx)
116 116
 {
117 117
     MergePlanesContext *s = ctx->priv;
118 118
     AVFilterFormats *formats = NULL;
119
-    int i;
119
+    int i, ret;
120 120
 
121 121
     s->outdesc = av_pix_fmt_desc_get(s->out_fmt);
122 122
     for (i = 0; av_pix_fmt_desc_get(i); i++) {
123 123
         const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(i);
124 124
         if (desc->comp[0].depth == s->outdesc->comp[0].depth &&
125
-            av_pix_fmt_count_planes(i) == desc->nb_components)
126
-            ff_add_format(&formats, i);
125
+            av_pix_fmt_count_planes(i) == desc->nb_components &&
126
+            (ret = ff_add_format(&formats, i)) < 0)
127
+                return ret;
127 128
     }
128 129
 
129 130
     for (i = 0; i < s->nb_inputs; i++)
130
-        ff_formats_ref(formats, &ctx->inputs[i]->out_formats);
131
+        if ((ret = ff_formats_ref(formats, &ctx->inputs[i]->out_formats)) < 0)
132
+            return ret;
131 133
 
132 134
     formats = NULL;
133
-    ff_add_format(&formats, s->out_fmt);
134
-    ff_formats_ref(formats, &ctx->outputs[0]->in_formats);
135
+    if ((ret = ff_add_format(&formats, s->out_fmt)) < 0 ||
136
+        (ret = ff_formats_ref(formats, &ctx->outputs[0]->in_formats)) < 0)
137
+        return ret;
135 138
 
136 139
     return 0;
137 140
 }
... ...
@@ -49,8 +49,7 @@ static int query_formats(AVFilterContext *ctx)
49 49
         AV_PIX_FMT_GBRP, AV_PIX_FMT_GBRAP, AV_PIX_FMT_GRAY8, AV_PIX_FMT_NONE
50 50
     };
51 51
 
52
-    ff_set_common_formats(ctx, ff_make_format_list(pix_fmts));
53
-    return 0;
52
+    return ff_set_common_formats(ctx, ff_make_format_list(pix_fmts));
54 53
 }
55 54
 
56 55
 static av_cold void uninit(AVFilterContext *ctx)
... ...
@@ -133,12 +133,13 @@ static av_cold int init_noise(NoiseContext *n, int comp)
133 133
 static int query_formats(AVFilterContext *ctx)
134 134
 {
135 135
     AVFilterFormats *formats = NULL;
136
-    int fmt;
136
+    int fmt, ret;
137 137
 
138 138
     for (fmt = 0; av_pix_fmt_desc_get(fmt); fmt++) {
139 139
         const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(fmt);
140
-        if (desc->flags & AV_PIX_FMT_FLAG_PLANAR && !(desc->comp[0].depth & 7))
141
-            ff_add_format(&formats, fmt);
140
+        if (desc->flags & AV_PIX_FMT_FLAG_PLANAR && !(desc->comp[0].depth & 7)
141
+            && (ret = ff_add_format(&formats, fmt)) < 0)
142
+                return ret;
142 143
     }
143 144
 
144 145
     return ff_set_common_formats(ctx, formats);
... ...
@@ -247,31 +247,37 @@ static int query_formats(AVFilterContext *ctx)
247 247
 
248 248
     AVFilterFormats *main_formats;
249 249
     AVFilterFormats *overlay_formats;
250
+    int ret;
250 251
 
251 252
     switch (s->format) {
252 253
     case OVERLAY_FORMAT_YUV420:
253
-        main_formats    = ff_make_format_list(main_pix_fmts_yuv420);
254
-        overlay_formats = ff_make_format_list(overlay_pix_fmts_yuv420);
254
+        if (!(main_formats    = ff_make_format_list(main_pix_fmts_yuv420)) ||
255
+            !(overlay_formats = ff_make_format_list(overlay_pix_fmts_yuv420)))
256
+            return AVERROR(ENOMEM);
255 257
         break;
256 258
     case OVERLAY_FORMAT_YUV422:
257
-        main_formats    = ff_make_format_list(main_pix_fmts_yuv422);
258
-        overlay_formats = ff_make_format_list(overlay_pix_fmts_yuv422);
259
+        if (!(main_formats    = ff_make_format_list(main_pix_fmts_yuv422)) ||
260
+            !(overlay_formats = ff_make_format_list(overlay_pix_fmts_yuv422)))
261
+            return AVERROR(ENOMEM);
259 262
         break;
260 263
     case OVERLAY_FORMAT_YUV444:
261
-        main_formats    = ff_make_format_list(main_pix_fmts_yuv444);
262
-        overlay_formats = ff_make_format_list(overlay_pix_fmts_yuv444);
264
+        if (!(main_formats    = ff_make_format_list(main_pix_fmts_yuv444)) ||
265
+            !(overlay_formats = ff_make_format_list(overlay_pix_fmts_yuv444)))
266
+            return AVERROR(ENOMEM);
263 267
         break;
264 268
     case OVERLAY_FORMAT_RGB:
265
-        main_formats    = ff_make_format_list(main_pix_fmts_rgb);
266
-        overlay_formats = ff_make_format_list(overlay_pix_fmts_rgb);
269
+        if (!(main_formats    = ff_make_format_list(main_pix_fmts_rgb)) ||
270
+            !(overlay_formats = ff_make_format_list(overlay_pix_fmts_rgb)))
271
+            return AVERROR(ENOMEM);
267 272
         break;
268 273
     default:
269 274
         av_assert0(0);
270 275
     }
271 276
 
272
-    ff_formats_ref(main_formats,    &ctx->inputs [MAIN   ]->out_formats);
273
-    ff_formats_ref(overlay_formats, &ctx->inputs [OVERLAY]->out_formats);
274
-    ff_formats_ref(main_formats,    &ctx->outputs[MAIN   ]->in_formats );
277
+    if ((ret = ff_formats_ref(main_formats   , &ctx->inputs[MAIN]->out_formats   )) < 0 ||
278
+        (ret = ff_formats_ref(overlay_formats, &ctx->inputs[OVERLAY]->out_formats)) < 0 ||
279
+        (ret = ff_formats_ref(main_formats   , &ctx->outputs[MAIN]->in_formats   )) < 0)
280
+        return ret;
275 281
 
276 282
     return 0;
277 283
 }
... ...
@@ -92,6 +92,7 @@ static int query_formats(AVFilterContext *ctx)
92 92
 {
93 93
     static const enum AVPixelFormat in_fmts[]  = {AV_PIX_FMT_RGB32, AV_PIX_FMT_NONE};
94 94
     static const enum AVPixelFormat out_fmts[] = {AV_PIX_FMT_RGB32, AV_PIX_FMT_NONE};
95
+    int ret;
95 96
     AVFilterFormats *in  = ff_make_format_list(in_fmts);
96 97
     AVFilterFormats *out = ff_make_format_list(out_fmts);
97 98
     if (!in || !out) {
... ...
@@ -99,8 +100,9 @@ static int query_formats(AVFilterContext *ctx)
99 99
         av_freep(&out);
100 100
         return AVERROR(ENOMEM);
101 101
     }
102
-    ff_formats_ref(in,  &ctx->inputs[0]->out_formats);
103
-    ff_formats_ref(out, &ctx->outputs[0]->in_formats);
102
+    if ((ret = ff_formats_ref(in , &ctx->inputs[0]->out_formats)) < 0 ||
103
+        (ret = ff_formats_ref(out, &ctx->outputs[0]->in_formats)) < 0)
104
+        return ret;
104 105
     return 0;
105 106
 }
106 107
 
... ...
@@ -132,6 +132,7 @@ static int query_formats(AVFilterContext *ctx)
132 132
     static const enum AVPixelFormat in_fmts[]    = {AV_PIX_FMT_RGB32, AV_PIX_FMT_NONE};
133 133
     static const enum AVPixelFormat inpal_fmts[] = {AV_PIX_FMT_RGB32, AV_PIX_FMT_NONE};
134 134
     static const enum AVPixelFormat out_fmts[]   = {AV_PIX_FMT_PAL8,  AV_PIX_FMT_NONE};
135
+    int ret;
135 136
     AVFilterFormats *in    = ff_make_format_list(in_fmts);
136 137
     AVFilterFormats *inpal = ff_make_format_list(inpal_fmts);
137 138
     AVFilterFormats *out   = ff_make_format_list(out_fmts);
... ...
@@ -141,9 +142,10 @@ static int query_formats(AVFilterContext *ctx)
141 141
         av_freep(&out);
142 142
         return AVERROR(ENOMEM);
143 143
     }
144
-    ff_formats_ref(in,    &ctx->inputs[0]->out_formats);
145
-    ff_formats_ref(inpal, &ctx->inputs[1]->out_formats);
146
-    ff_formats_ref(out,   &ctx->outputs[0]->in_formats);
144
+    if ((ret = ff_formats_ref(in   , &ctx->inputs[0]->out_formats)) < 0 ||
145
+        (ret = ff_formats_ref(inpal, &ctx->inputs[1]->out_formats)) < 0 ||
146
+        (ret = ff_formats_ref(out  , &ctx->outputs[0]->in_formats)) < 0)
147
+        return ret;
147 148
     return 0;
148 149
 }
149 150
 
... ...
@@ -188,11 +188,11 @@ static int query_formats(AVFilterContext *ctx)
188 188
             if ((sws_isSupportedInput(pix_fmt) ||
189 189
                  sws_isSupportedEndiannessConversion(pix_fmt))
190 190
                 && (ret = ff_add_format(&formats, pix_fmt)) < 0) {
191
-                ff_formats_unref(&formats);
192 191
                 return ret;
193 192
             }
194 193
         }
195
-        ff_formats_ref(formats, &ctx->inputs[0]->out_formats);
194
+        if ((ret = ff_formats_ref(formats, &ctx->inputs[0]->out_formats)) < 0)
195
+            return ret;
196 196
     }
197 197
     if (ctx->outputs[0]) {
198 198
         const AVPixFmtDescriptor *desc = NULL;
... ...
@@ -202,11 +202,11 @@ static int query_formats(AVFilterContext *ctx)
202 202
             if ((sws_isSupportedOutput(pix_fmt) || pix_fmt == AV_PIX_FMT_PAL8 ||
203 203
                  sws_isSupportedEndiannessConversion(pix_fmt))
204 204
                 && (ret = ff_add_format(&formats, pix_fmt)) < 0) {
205
-                ff_formats_unref(&formats);
206 205
                 return ret;
207 206
             }
208 207
         }
209
-        ff_formats_ref(formats, &ctx->outputs[0]->in_formats);
208
+        if ((ret = ff_formats_ref(formats, &ctx->outputs[0]->in_formats)) < 0)
209
+            return ret;
210 210
     }
211 211
 
212 212
     return 0;
... ...
@@ -46,6 +46,7 @@ static int query_formats(AVFilterContext *ctx)
46 46
 {
47 47
     static const enum AVPixelFormat in_fmts[]  = {AV_PIX_FMT_PAL8,  AV_PIX_FMT_NONE};
48 48
     static const enum AVPixelFormat out_fmts[] = {AV_PIX_FMT_RGB32, AV_PIX_FMT_NONE};
49
+    int ret;
49 50
     AVFilterFormats *in  = ff_make_format_list(in_fmts);
50 51
     AVFilterFormats *out = ff_make_format_list(out_fmts);
51 52
     if (!in || !out) {
... ...
@@ -53,8 +54,9 @@ static int query_formats(AVFilterContext *ctx)
53 53
         av_freep(&out);
54 54
         return AVERROR(ENOMEM);
55 55
     }
56
-    ff_formats_ref(in,  &ctx->inputs[0]->out_formats);
57
-    ff_formats_ref(out, &ctx->outputs[0]->in_formats);
56
+    if ((ret = ff_formats_ref(in , &ctx->inputs[0]->out_formats)) < 0 ||
57
+        (ret = ff_formats_ref(out, &ctx->outputs[0]->in_formats)) < 0)
58
+        return ret;
58 59
     return 0;
59 60
 }
60 61
 
... ...
@@ -43,14 +43,15 @@ typedef struct StackContext {
43 43
 static int query_formats(AVFilterContext *ctx)
44 44
 {
45 45
     AVFilterFormats *pix_fmts = NULL;
46
-    int fmt;
46
+    int fmt, ret;
47 47
 
48 48
     for (fmt = 0; av_pix_fmt_desc_get(fmt); fmt++) {
49 49
         const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(fmt);
50 50
         if (!(desc->flags & AV_PIX_FMT_FLAG_PAL ||
51 51
               desc->flags & AV_PIX_FMT_FLAG_HWACCEL ||
52
-              desc->flags & AV_PIX_FMT_FLAG_BITSTREAM))
53
-            ff_add_format(&pix_fmts, fmt);
52
+              desc->flags & AV_PIX_FMT_FLAG_BITSTREAM) &&
53
+            (ret = ff_add_format(&pix_fmts, fmt)) < 0)
54
+            return ret;
54 55
     }
55 56
 
56 57
     return ff_set_common_formats(ctx, pix_fmts);
... ...
@@ -77,12 +77,12 @@ static int is_planar_yuv(const AVPixFmtDescriptor *desc)
77 77
 static int query_formats(AVFilterContext *ctx)
78 78
 {
79 79
     AVFilterFormats *formats = NULL;
80
-    int fmt;
80
+    int fmt, ret;
81 81
 
82 82
     for (fmt = 0; av_pix_fmt_desc_get(fmt); fmt++) {
83 83
         const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(fmt);
84
-        if (is_planar_yuv(desc))
85
-            ff_add_format(&formats, fmt);
84
+        if (is_planar_yuv(desc) && (ret = ff_add_format(&formats, fmt)) < 0)
85
+            return ret;
86 86
     }
87 87
 
88 88
     return ff_set_common_formats(ctx, formats);
... ...
@@ -102,14 +102,15 @@ static av_cold int init(AVFilterContext *ctx)
102 102
 static int query_formats(AVFilterContext *ctx)
103 103
 {
104 104
     AVFilterFormats *pix_fmts = NULL;
105
-    int fmt;
105
+    int fmt, ret;
106 106
 
107 107
     for (fmt = 0; av_pix_fmt_desc_get(fmt); fmt++) {
108 108
         const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(fmt);
109 109
         if (!(desc->flags & AV_PIX_FMT_FLAG_HWACCEL ||
110 110
               desc->flags & AV_PIX_FMT_FLAG_PAL     ||
111
-              desc->flags & AV_PIX_FMT_FLAG_BITSTREAM))
112
-            ff_add_format(&pix_fmts, fmt);
111
+              desc->flags & AV_PIX_FMT_FLAG_BITSTREAM) &&
112
+            (ret = ff_add_format(&pix_fmts, fmt)) < 0)
113
+            return ret;
113 114
     }
114 115
 
115 116
     return ff_set_common_formats(ctx, pix_fmts);
... ...
@@ -63,15 +63,16 @@ typedef struct TransContext {
63 63
 static int query_formats(AVFilterContext *ctx)
64 64
 {
65 65
     AVFilterFormats *pix_fmts = NULL;
66
-    int fmt;
66
+    int fmt, ret;
67 67
 
68 68
     for (fmt = 0; av_pix_fmt_desc_get(fmt); fmt++) {
69 69
         const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(fmt);
70 70
         if (!(desc->flags & AV_PIX_FMT_FLAG_PAL ||
71 71
               desc->flags & AV_PIX_FMT_FLAG_HWACCEL ||
72 72
               desc->flags & AV_PIX_FMT_FLAG_BITSTREAM ||
73
-              desc->log2_chroma_w != desc->log2_chroma_h))
74
-            ff_add_format(&pix_fmts, fmt);
73
+              desc->log2_chroma_w != desc->log2_chroma_h) &&
74
+            (ret = ff_add_format(&pix_fmts, fmt)) < 0)
75
+            return ret;
75 76
     }
76 77
 
77 78
 
... ...
@@ -140,7 +140,7 @@ static int query_formats(AVFilterContext *ctx)
140 140
     const enum AVPixelFormat *out_pix_fmts;
141 141
     const AVPixFmtDescriptor *desc;
142 142
     AVFilterFormats *avff;
143
-    int depth, rgb, i;
143
+    int depth, rgb, i, ret;
144 144
 
145 145
     if (!ctx->inputs[0]->in_formats ||
146 146
         !ctx->inputs[0]->in_formats->nb_formats) {
... ...
@@ -154,7 +154,8 @@ static int query_formats(AVFilterContext *ctx)
154 154
             in_pix_fmts = in2_pix_fmts;
155 155
         else
156 156
             in_pix_fmts = in1_pix_fmts;
157
-        ff_formats_ref(ff_make_format_list(in_pix_fmts), &ctx->inputs[0]->out_formats);
157
+        if ((ret = ff_formats_ref(ff_make_format_list(in_pix_fmts), &ctx->inputs[0]->out_formats)) < 0)
158
+            return ret;
158 159
     }
159 160
 
160 161
     avff = ctx->inputs[0]->in_formats;
... ...
@@ -180,7 +181,8 @@ static int query_formats(AVFilterContext *ctx)
180 180
         out_pix_fmts = out_yuv10_pix_fmts;
181 181
     else
182 182
         out_pix_fmts = out_yuv8_pix_fmts;
183
-    ff_formats_ref(ff_make_format_list(out_pix_fmts), &ctx->outputs[0]->in_formats);
183
+    if ((ret = ff_formats_ref(ff_make_format_list(out_pix_fmts), &ctx->outputs[0]->in_formats)) < 0)
184
+        return ret;
184 185
 
185 186
     return 0;
186 187
 }
... ...
@@ -428,10 +428,7 @@ static int query_formats(AVFilterContext *ctx)
428 428
     }
429 429
 
430 430
     fmts_list = ff_make_format_list(pix_fmts);
431
-    if (!fmts_list)
432
-        return AVERROR(ENOMEM);
433
-    ff_set_common_formats(ctx, fmts_list);
434
-    return 0;
431
+    return ff_set_common_formats(ctx, fmts_list);
435 432
 }
436 433
 
437 434
 static const AVFilterPad life_outputs[] = {