From 0bc0a5a622c547cfde204766d72f44dc7c435afd Mon Sep 17 00:00:00 2001 From: Jan Schmidt Date: Tue, 31 Jul 2007 11:51:38 +0000 Subject: [PATCH] gst/gstregistry.c: When replacing an existing feature in the registry, make sure to continue holding a reference unti... 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 | 10 ++++++++++ gst/gstregistry.c | 11 ++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3499df1c7e..4f2ac8f2da 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2007-07-31 Jan Schmidt + + * 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 * gst/gstpluginfeature.c: (gst_plugin_feature_finalize), diff --git a/gst/gstregistry.c b/gst/gstregistry.c index 0ba36d43c9..553da6b441 100644 --- a/gst/gstregistry.c +++ b/gst/gstregistry.c @@ -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);