diff --git a/libavfilter/avfiltergraph.c b/libavfilter/avfiltergraph.c
index 0101d650a67b67143070c2e088365c134bdb31ff..75e828feebf61c8e0a79eadafcfbbe52c34c61c2 100644
--- a/libavfilter/avfiltergraph.c
+++ b/libavfilter/avfiltergraph.c
@@ -84,6 +84,10 @@ int avfilter_graph_add_filter(AVFilterGraph *graph, AVFilterContext *filter)
     graph->filters = filters;
     graph->filters[graph->nb_filters++] = filter;
 
+#if FF_API_FOO_COUNT
+    graph->filter_count_unused = graph->nb_filters;
+#endif
+
     return 0;
 }
 
diff --git a/libavformat/utils.c b/libavformat/utils.c
index c5d6d322c3fc072a7567a1c7952f1e90abe9f873..e32f97288dec6d5af70ffae96a05f166ffd96c28 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -3274,6 +3274,7 @@ void ff_free_stream(AVFormatContext *s, AVStream *st){
     if (st->attached_pic.data)
         av_free_packet(&st->attached_pic);
     av_dict_free(&st->metadata);
+    av_freep(&st->probe_data.buf);
     av_freep(&st->index_entries);
     av_freep(&st->codec->extradata);
     av_freep(&st->codec->subtitle_header);
@@ -3282,7 +3283,6 @@ void ff_free_stream(AVFormatContext *s, AVStream *st){
     if (st->info)
         av_freep(&st->info->duration_error);
     av_freep(&st->info);
-    av_freep(&st->probe_data.buf);
     av_freep(&s->streams[ --s->nb_streams ]);
 }