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.
Unified · Split
| @@ -2698,10 +2698,7 @@ static int transcode(AVFormatContext **output_files, · 2697 unmodified lines | ||
| 2698 | 2698 | } |
| 2699 | 2699 | } |
| 2700 | 2700 | #if CONFIG_AVFILTER |
| 2701 | − if (graph) { | |
| 2702 | − avfilter_graph_free(graph); | |
| 2703 | − av_freep(&graph); | |
| 2704 | − } | |
| 2701 | + avfilter_graph_free(&graph); | |
| 2705 | 2702 | #endif |
| 2706 | 2703 | |
| 2707 | 2704 | /* finished ! */ |
| @@ -1899,8 +1899,7 @@ static int video_thread(void *arg) · 1898 unmodified lines | ||
| 1899 | 1899 | } |
| 1900 | 1900 | the_end: |
| 1901 | 1901 | #if CONFIG_AVFILTER |
| 1902 | − avfilter_graph_free(graph); | |
| 1903 | − av_freep(&graph); | |
| 1902 | + avfilter_graph_free(&graph); | |
| 1904 | 1903 | #endif |
| 1905 | 1904 | av_free(frame); |
| 1906 | 1905 | return 0; |
| @@ -32,14 +32,15 @@ AVFilterGraph *avfilter_graph_alloc(void) · 31 unmodified lines | ||
| 32 | 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 | 38 | return; |
| 39 | − for (; graph->filter_count > 0; graph->filter_count --) | |
| 40 | − avfilter_free(graph->filters[graph->filter_count - 1]); | |
| 41 | − av_freep(&graph->scale_sws_opts); | |
| 42 | − av_freep(&graph->filters); | |
| 39 | + for (; (*graph)->filter_count > 0; (*graph)->filter_count--) | |
| 40 | + avfilter_free((*graph)->filters[(*graph)->filter_count - 1]); | |
| 41 | + av_freep(&(*graph)->scale_sws_opts); | |
| 42 | + av_freep(&(*graph)->filters); | |
| 43 | + av_freep(graph); | |
| 43 | 44 | } |
| 44 | 45 | |
| 45 | 46 | int avfilter_graph_add_filter(AVFilterGraph *graph, AVFilterContext *filter) |
| @@ -79,9 +79,10 @@ int avfilter_graph_create_filter(AVFilterContext **filt_ctx, AVFilter *filt, · 78 unmodified lines | ||
| 79 | 79 | int avfilter_graph_config(AVFilterGraph *graphctx, AVClass *log_ctx); |
| 80 | 80 | |
| 81 | 81 | /** |
| 82 | − * Free a graph and destroy its links, graph may be NULL. | |
| 82 | + * Free a graph, destroy its links, and set *graph to NULL. | |
| 83 | + * If *graph is NULL, do nothing. | |
| 83 | 84 | */ |
| 84 | −void avfilter_graph_free(AVFilterGraph *graph); | |
| 85 | +void avfilter_graph_free(AVFilterGraph **graph); | |
| 85 | 86 | |
| 86 | 87 | /** |
| 87 | 88 | * A linked-list of the inputs/outputs of the filter chain. |