Browse code

Fix leak in avfilter_graph_add_filter().

In case of reallocation failure the pointer to the original filter
array was lost. The correct behavior seems to just keep the old array
and count.

Originally committed as revision 22905 to svn://svn.ffmpeg.org/ffmpeg/trunk

Stefano Sabatini authored on 2010/04/19 05:10:43
Showing 1 changed files
... ...
@@ -36,13 +36,13 @@ void avfilter_graph_destroy(AVFilterGraph *graph)
36 36
 
37 37
 int avfilter_graph_add_filter(AVFilterGraph *graph, AVFilterContext *filter)
38 38
 {
39
-    graph->filters = av_realloc(graph->filters,
40
-                                sizeof(AVFilterContext*) * ++graph->filter_count);
41
-
42
-    if (!graph->filters)
39
+    AVFilterContext **filters = av_realloc(graph->filters,
40
+                                           sizeof(AVFilterContext*) * (graph->filter_count+1));
41
+    if (!filters)
43 42
         return AVERROR(ENOMEM);
44 43
 
45
-    graph->filters[graph->filter_count - 1] = filter;
44
+    graph->filters = filters;
45
+    graph->filters[graph->filter_count++] = filter;
46 46
 
47 47
     return 0;
48 48
 }