Make avfilter_graph_free() free not only the internal structures, but also the allocated graph, and set the graph pointer to NULL for increased safety. Simplify usage.
Showing the changes to libavfilter/avfiltergraph.c (1 of 4 files). Show all
Unified · Split
| @@ -32,14 +32,15 @@ AVFilterGraph *avfilter_graph_alloc(void) · 31 unmodified lines | |||
| 32 | return av_mallocz(sizeof(AVFilterGraph)); | 32 | return av_mallocz(sizeof(AVFilterGraph)); |
| 33 | } | 33 | } |
| 34 | 34 | ||
| 35 | void avfilter_graph_free(AVFilterGraph *graph) | 35 | void avfilter_graph_free(AVFilterGraph **graph) |
| 36 | { | 36 | { |
| 37 | if (!graph) | 37 | if (!*graph) |
| 38 | return; | 38 | return; |
| 39 | for (; graph->filter_count > 0; graph->filter_count --) | 39 | for (; (*graph)->filter_count > 0; (*graph)->filter_count--) |
| 40 | avfilter_free(graph->filters[graph->filter_count - 1]); | 40 | avfilter_free((*graph)->filters[(*graph)->filter_count - 1]); |
| 41 | av_freep(&graph->scale_sws_opts); | 41 | av_freep(&(*graph)->scale_sws_opts); |
| 42 | av_freep(&graph->filters); | 42 | av_freep(&(*graph)->filters); |
| 43 | av_freep(graph); | ||
| 43 | } | 44 | } |
| 44 | 45 | ||
| 45 | int avfilter_graph_add_filter(AVFilterGraph *graph, AVFilterContext *filter) | 46 | int avfilter_graph_add_filter(AVFilterGraph *graph, AVFilterContext *filter) |