From 83a815e648ee4c301ab81f964a4667e8797b9e8d Mon Sep 17 00:00:00 2001 From: Michael Smith Date: Mon, 12 Dec 2005 19:09:49 +0000 Subject: [PATCH] gst/gsttypefindfactory.c: Don't unref factories after calling them. Original commit message from CVS: * gst/gsttypefindfactory.c: (gst_type_find_factory_call_function): Don't unref factories after calling them. * libs/gst/base/gsttypefindhelper.c: (gst_type_find_helper): * plugins/elements/gsttypefindelement.c: (gst_type_find_element_chain): Free lists of factories after using them. Fixing typefinding memory leaks. --- ChangeLog | 10 ++++++ gst/gsttypefindfactory.c | 1 - libs/gst/base/gsttypefindhelper.c | 1 + plugins/elements/gsttypefindelement.c | 47 ++++++++++++--------------- 4 files changed, 32 insertions(+), 27 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9673f94bbc..1d19114afc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2005-12-12 Michael Smith + + * gst/gsttypefindfactory.c: (gst_type_find_factory_call_function): + Don't unref factories after calling them. + * libs/gst/base/gsttypefindhelper.c: (gst_type_find_helper): + * plugins/elements/gsttypefindelement.c: + (gst_type_find_element_chain): + Free lists of factories after using them. Fixing typefinding memory + leaks. + 2005-12-12 Stefan Kost * gst/gstpluginfeature.c: (gst_plugin_feature_finalize), diff --git a/gst/gsttypefindfactory.c b/gst/gsttypefindfactory.c index 481afe0f1c..47850fd077 100644 --- a/gst/gsttypefindfactory.c +++ b/gst/gsttypefindfactory.c @@ -239,6 +239,5 @@ gst_type_find_factory_call_function (GstTypeFindFactory * factory, g_assert (new_factory->function != NULL); new_factory->function (find, new_factory->user_data); - gst_object_unref (new_factory); } } diff --git a/libs/gst/base/gsttypefindhelper.c b/libs/gst/base/gsttypefindhelper.c index 6656c061d5..b802a747e2 100644 --- a/libs/gst/base/gsttypefindhelper.c +++ b/libs/gst/base/gsttypefindhelper.c @@ -170,6 +170,7 @@ gst_type_find_helper (GstPad * src, guint64 size) break; walk = g_list_next (walk); } + gst_plugin_feature_list_free (type_list); if (find.best_probability > 0) result = find.caps; diff --git a/plugins/elements/gsttypefindelement.c b/plugins/elements/gsttypefindelement.c index 333880e776..8f66813e71 100644 --- a/plugins/elements/gsttypefindelement.c +++ b/plugins/elements/gsttypefindelement.c @@ -641,7 +641,6 @@ static GstFlowReturn gst_type_find_element_chain (GstPad * pad, GstBuffer * buffer) { GstTypeFindElement *typefind; - GList *entries; TypeFindEntry *entry; GList *walk; GstFlowReturn res = GST_FLOW_OK; @@ -687,26 +686,31 @@ gst_type_find_element_chain (GstPad * pad, GstBuffer * buffer) } /* call every typefind function once */ - walk = entries = typefind->possibilities; + walk = typefind->possibilities; GST_INFO_OBJECT (typefind, "iterating %u typefinding functions", - g_list_length (entries)); - typefind->possibilities = NULL; + g_list_length (walk)); while (walk) { find.data = entry = (TypeFindEntry *) walk->data; - walk = g_list_next (walk); - if (entry->probability == 0) { - entry->requested_size = 0; - gst_type_find_factory_call_function (entry->factory, &find); - } else { - typefind->possibilities = - g_list_prepend (typefind->possibilities, entry); + if (entry->probability != 0) { + /* Probability already known, just continue along the list */ + walk = g_list_next (walk); continue; } + + entry->requested_size = 0; + gst_type_find_factory_call_function (entry->factory, &find); + if (entry->probability == 0 && entry->requested_size == 0) { + GList *next; + GST_DEBUG_OBJECT (typefind, "'%s' was removed - no chance of being the right plugin", GST_PLUGIN_FEATURE_NAME (entry->factory)); + next = g_list_next (walk); free_entry (entry); + typefind->possibilities = + g_list_delete_link (typefind->possibilities, walk); + walk = next; } else if (entry->probability >= typefind->max_probability) { /* wooha, got caps */ GstCaps *found_caps = entry->caps; @@ -716,28 +720,19 @@ gst_type_find_element_chain (GstPad * pad, GstBuffer * buffer) "'%s' returned %u/%u probability, using it NOW", GST_PLUGIN_FEATURE_NAME (entry->factory), probability, typefind->max_probability); - while (walk) { - free_entry ((TypeFindEntry *) walk->data); - walk = g_list_next (walk); - } - walk = typefind->possibilities; - while (walk) { - free_entry (walk->data); - walk = g_list_next (walk); - } - g_list_free (typefind->possibilities); - typefind->possibilities = NULL; g_signal_emit (typefind, gst_type_find_element_signals[HAVE_TYPE], 0, probability, found_caps); - free_entry (entry); + + g_list_foreach (typefind->possibilities, (GFunc) free_entry, NULL); + g_list_free (typefind->possibilities); + typefind->possibilities = NULL; + break; } else { - typefind->possibilities = - g_list_prepend (typefind->possibilities, entry); + walk = g_list_next (walk); if (entry->requested_size != 0) done = FALSE; } } - g_list_free (entries); /* we may now already have caps or we might be left without functions to try */ if (typefind->caps) {