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.
Showing the changes to libavfilter/avfiltergraph.c (1 of 1 file). Show all
Unified · Split
| @@ -183,17 +183,15 @@ AVFilterContext *avfilter_graph_alloc_filter(AVFilterGraph *graph, · 182 unmodified lines | ||
| 183 | 183 | } |
| 184 | 184 | } |
| 185 | 185 | |
| 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) | |
| 188 | 188 | return NULL; |
| 189 | + graph->filters = filters; | |
| 189 | 190 | |
| 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) | |
| 193 | 193 | return NULL; |
| 194 | − } | |
| 195 | 194 | |
| 196 | − graph->filters = filters; | |
| 197 | 195 | graph->filters[graph->nb_filters++] = s; |
| 198 | 196 | |
| 199 | 197 | s->graph = graph; |