summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2021-09-28 08:07:43 +0200
committerAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2021-10-02 16:20:21 +0200
commit22c4f3399133a62aa11f4af01e7dacea08d4ddae (patch)
treeb1694e2e65ae56483ca37740a187197a42ff0444
parent68815d67919a6975357ad214d8fe8ac4c886e47c (diff)
avfilter/avfiltergraph: Simplify adding filter to graph
By reallocating the array of pointers to the AVFilterContexts before allocating the new AVFilterContext one can avoid freeing the new AVFilterContext in case the array could not be reallocated. Also switch to av_realloc_array() while just at it. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
-rw-r--r--libavfilter/avfiltergraph.c12
1 files changed, 5 insertions, 7 deletions
diff --git a/libavfilter/avfiltergraph.c b/libavfilter/avfiltergraph.c
index 45b028cd9c..ee0c82030d 100644
--- a/libavfilter/avfiltergraph.c
+++ b/libavfilter/avfiltergraph.c
@@ -183,17 +183,15 @@ AVFilterContext *avfilter_graph_alloc_filter(AVFilterGraph *graph,
}
}
- s = ff_filter_alloc(filter, name);
- if (!s)
+ filters = av_realloc_array(graph->filters, graph->nb_filters + 1, sizeof(*filters));
+ if (!filters)
return NULL;
+ graph->filters = filters;
- filters = av_realloc(graph->filters, sizeof(*filters) * (graph->nb_filters + 1));
- if (!filters) {
- avfilter_free(s);
+ s = ff_filter_alloc(filter, name);
+ if (!s)
return NULL;
- }
- graph->filters = filters;
graph->filters[graph->nb_filters++] = s;
s->graph = graph;