[PATCH] Make avfilter_graph_free() free the graph.

Stefano Sabatini stefano.sabatini-lala
Tue Feb 1 20:02:17 CET 2011


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.
---
 ffmpeg.c                    |    5 +----
 ffplay.c                    |    3 +--
 libavfilter/avfiltergraph.c |   13 +++++++------
 libavfilter/avfiltergraph.h |    5 +++--
 4 files changed, 12 insertions(+), 14 deletions(-)

diff --git a/ffmpeg.c b/ffmpeg.c
index df89018..5de0e5e 100644
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -2698,10 +2698,7 @@ static int transcode(AVFormatContext **output_files,
         }
     }
 #if CONFIG_AVFILTER
-    if (graph) {
-        avfilter_graph_free(graph);
-        av_freep(&graph);
-    }
+    avfilter_graph_free(&graph);
 #endif
 
     /* finished ! */
diff --git a/ffplay.c b/ffplay.c
index 1b5ab0b..392c7cc 100644
--- a/ffplay.c
+++ b/ffplay.c
@@ -1899,8 +1899,7 @@ static int video_thread(void *arg)
     }
  the_end:
 #if CONFIG_AVFILTER
-    avfilter_graph_free(graph);
-    av_freep(&graph);
+    avfilter_graph_free(&graph);
 #endif
     av_free(frame);
     return ret;
diff --git a/libavfilter/avfiltergraph.c b/libavfilter/avfiltergraph.c
index a62fe2f..bdf22b3 100644
--- a/libavfilter/avfiltergraph.c
+++ b/libavfilter/avfiltergraph.c
@@ -32,14 +32,15 @@ AVFilterGraph *avfilter_graph_alloc(void)
     return av_mallocz(sizeof(AVFilterGraph));
 }
 
-void avfilter_graph_free(AVFilterGraph *graph)
+void avfilter_graph_free(AVFilterGraph **graph)
 {
-    if (!graph)
+    if (!*graph)
         return;
-    for (; graph->filter_count > 0; graph->filter_count --)
-        avfilter_free(graph->filters[graph->filter_count - 1]);
-    av_freep(&graph->scale_sws_opts);
-    av_freep(&graph->filters);
+    for (; (*graph)->filter_count > 0; (*graph)->filter_count--)
+        avfilter_free((*graph)->filters[(*graph)->filter_count - 1]);
+    av_freep(&(*graph)->scale_sws_opts);
+    av_freep(&(*graph)->filters);
+    av_freep(graph);
 }
 
 int avfilter_graph_add_filter(AVFilterGraph *graph, AVFilterContext *filter)
diff --git a/libavfilter/avfiltergraph.h b/libavfilter/avfiltergraph.h
index 1b0d242..0140af0 100644
--- a/libavfilter/avfiltergraph.h
+++ b/libavfilter/avfiltergraph.h
@@ -79,9 +79,10 @@ int avfilter_graph_create_filter(AVFilterContext **filt_ctx, AVFilter *filt,
 int avfilter_graph_config(AVFilterGraph *graphctx, AVClass *log_ctx);
 
 /**
- * Free a graph and destroy its links, graph may be NULL.
+ * Free a graph, destroy its links, and set *graph to NULL.
+ * If *graph is NULL, do nothing.
  */
-void avfilter_graph_free(AVFilterGraph *graph);
+void avfilter_graph_free(AVFilterGraph **graph);
 
 /**
  * A linked-list of the inputs/outputs of the filter chain.
-- 
1.7.2.3


--ibTvN161/egqYuK8--



More information about the ffmpeg-devel mailing list