History

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.

Andreas Rheinhardt committed 5 years ago

Commit 22c4f331 parent 68815d61 file · +5 −7Browse files

Showing the changes to libavfilter/avfiltergraph.c (1 of 1 file). Show all

Unified · Split

libavfilter/avfiltergraph.c+5−7
@@ -183,17 +183,15 @@ AVFilterContext *avfilter_graph_alloc_filter(AVFilterGraph *graph, · 182 unmodified lines
183183 }
184184 }
185185
186− s = ff_filter_alloc(filter, name);
187− if (!s)
186+ filters = av_realloc_array(graph->filters, graph->nb_filters + 1, sizeof(*filters));
187+ if (!filters)
188188 return NULL;
189+ graph->filters = filters;
189190
190− filters = av_realloc(graph->filters, sizeof(*filters) * (graph->nb_filters + 1));
191− if (!filters) {
192− avfilter_free(s);
191+ s = ff_filter_alloc(filter, name);
192+ if (!s)
193193 return NULL;
194− }
195194
196− graph->filters = filters;
197195 graph->filters[graph->nb_filters++] = s;
198196
199197 s->graph = graph;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t