gst/gstregistry.c: When replacing an existing feature in the registry, make sure...
authorJan Schmidt <thaytan@mad.scientist.com>
Tue, 31 Jul 2007 11:51:38 +0000 (11:51 +0000)
committerJan Schmidt <thaytan@mad.scientist.com>
Tue, 31 Jul 2007 11:51:38 +0000 (11:51 +0000)
Original commit message from CVS:
* gst/gstregistry.c: (gst_registry_add_feature):
When replacing an existing feature in the registry, make sure to
continue holding a reference until we've replaced the name string
within our feature hash table. Make sure to use g_hash_table_replace
instead of g_hash_table_insert to ensure the new name string is used
as a key instead of the old one that we're about to free.
Fixes: #462085

ChangeLog
gst/gstregistry.c

index 3499df1..4f2ac8f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
 2007-07-31  Jan Schmidt  <thaytan@mad.scientist.com>
 
+       * gst/gstregistry.c: (gst_registry_add_feature):
+       When replacing an existing feature in the registry, make sure to
+       continue holding a reference until we've replaced the name string
+       within our feature hash table. Make sure to use g_hash_table_replace
+       instead of g_hash_table_insert to ensure the new name string is used
+       as a key instead of the old one that we're about to free.
+       Fixes: #462085
+
+2007-07-31  Jan Schmidt  <thaytan@mad.scientist.com>
+
        * gst/gstpluginfeature.c: (gst_plugin_feature_finalize),
        (gst_plugin_feature_set_name):
        Revert patch from #459466 until after the release and we can work
index 0ba36d4..553da6b 100644 (file)
@@ -445,15 +445,20 @@ gst_registry_add_feature (GstRegistry * registry, GstPluginFeature * feature)
   if (G_UNLIKELY (existing_feature)) {
     GST_DEBUG_OBJECT (registry, "replacing existing feature %p (%s)",
         existing_feature, feature->name);
+    /* Remove the existing feature from the list now, before we insert the new
+     * one, but don't unref yet because the hash is still storing a reference to     * it. */
     registry->features = g_list_remove (registry->features, existing_feature);
-    /* no need to remove from feature_hash, as insert will replace the value */
-    gst_object_unref (existing_feature);
   }
 
   GST_DEBUG_OBJECT (registry, "adding feature %p (%s)", feature, feature->name);
 
   registry->features = g_list_prepend (registry->features, feature);
-  g_hash_table_insert (registry->feature_hash, feature->name, feature);
+  g_hash_table_replace (registry->feature_hash, feature->name, feature);
+
+  if (G_UNLIKELY (existing_feature)) {
+    /* We unref now. No need to remove the feature name from the hash table, it      * got replaced by the new feature */
+    gst_object_unref (existing_feature);
+  }
 
   gst_object_ref (feature);
   gst_object_sink (feature);