Index: gst/gst.h
===================================================================
RCS file: /cvs/gstreamer/gstreamer/gst/gst.h,v
retrieving revision 1.97
diff -u -p -r1.97 gst.h
--- gst/gst.h	11 Aug 2006 10:19:51 -0000	1.97
+++ gst/gst.h	31 Dec 2006 13:54:18 -0000
@@ -91,6 +91,8 @@ void            gst_segtrap_set_enabled 
 gboolean        gst_registry_fork_is_enabled    (void);
 void            gst_registry_fork_set_enabled   (gboolean enabled);
 
+gboolean        gst_update_registry (void);
+
 G_END_DECLS
 
 #endif /* __GST_H__ */
Index: gst/gst.c
===================================================================
RCS file: /cvs/gstreamer/gstreamer/gst/gst.c,v
retrieving revision 1.232
diff -u -p -r1.232 gst.c
--- gst/gst.c	19 Dec 2006 11:04:49 -0000	1.232
+++ gst/gst.c	31 Dec 2006 13:54:19 -0000
@@ -468,8 +468,6 @@ load_plugin_func (gpointer data, gpointe
       GST_WARNING ("Failed to load plugin: \"%s\"", filename);
     }
   }
-
-  g_free (data);
 }
 
 static void
@@ -624,10 +622,8 @@ scan_and_update_registry (GstRegistry * 
     GST_INFO ("Scanning plugin path: \"%s\"", (gchar *) l->data);
     /* CHECKME: add changed |= here as well? */
     gst_registry_scan_path (default_registry, (gchar *) l->data);
-    g_free (l->data);
   }
-  g_list_free (plugin_paths);
-  plugin_paths = NULL;
+  /* keep plugin_paths around in case a re-scan is forced later on */
 
   /* GST_PLUGIN_PATH specifies a list of directories to scan for
    * additional plugins.  These take precedence over the system plugins */
@@ -934,12 +930,10 @@ init_post (GOptionContext * context, GOp
     return FALSE;
 #endif /* GST_DISABLE_REGISTRY */
 
-  /* if we need to preload plugins */
-  if (preload_plugins) {
-    g_slist_foreach (preload_plugins, load_plugin_func, NULL);
-    g_slist_free (preload_plugins);
-    preload_plugins = NULL;
-  }
+  /* if we need to preload plugins, do so now */
+  g_slist_foreach (preload_plugins, load_plugin_func, NULL);
+  /* keep preload_plugins around in case a re-scan is forced later on */
+
 #ifndef GST_DISABLE_TRACE
   _gst_trace_on = 0;
   if (_gst_trace_on) {
@@ -1147,6 +1141,15 @@ gst_deinit (void)
     return;
   }
 
+  g_slist_foreach (preload_plugins, (GFunc) g_free, NULL);
+  g_slist_free (preload_plugins);
+  preload_plugins = NULL;
+
+  g_list_foreach (plugin_paths, (GFunc) g_free, NULL);
+  g_list_free (plugin_paths);
+  plugin_paths = NULL;
+
+
   clock = gst_system_clock_obtain ();
   gst_object_unref (clock);
   gst_object_unref (clock);
@@ -1280,3 +1283,52 @@ gst_registry_fork_set_enabled (gboolean 
   _gst_enable_registry_fork = enabled;
 #endif /* HAVE_FORK */
 }
+
+
+/**
+ * gst_update_registry:
+ *
+ * Forces GStreamer to re-scan its plugin paths and update the default
+ * plugin registry.
+ *
+ * Applications will almost never need to call this function, it is only
+ * useful if the application knows new plugins have been installed (or old
+ * ones removed) since the start of the application (or, to be precise, the
+ * first call to gst_init()) and the application wants to make use of any
+ * newly-installed plugins without restarting the application.
+ *
+ * Note that this function may block for a significant amount of time.
+ *
+ * Returns: %TRUE if the registry has been updated successfully (does not
+ *          imply that there were changes), otherwise %FALSE.
+ *
+ * Since: 0.10.12
+ */
+gboolean
+gst_update_registry (void)
+{
+  gboolean res = FALSE;
+
+#ifndef GST_DISABLE_REGISTRY
+  GError *err = NULL;
+
+  res = ensure_current_registry (&err);
+  if (err) {
+    GST_WARNING ("registry update failed: %s", err->message);
+    g_error_free (err);
+  } else {
+    GST_LOG ("registry update succeeded");
+  }
+
+  if (preload_plugins) {
+    g_slist_foreach (preload_plugins, load_plugin_func, NULL);
+  }
+
+#else
+  GST_WARNING ("registry update failed: %s", "registry disabled");
+#endif /* GST_DISABLE_REGISTRY */
+
+  return res;
+}
+
+
Index: docs/gst/gstreamer-sections.txt
===================================================================
RCS file: /cvs/gstreamer/gstreamer/docs/gst/gstreamer-sections.txt,v
retrieving revision 1.279
diff -u -p -r1.279 gstreamer-sections.txt
--- docs/gst/gstreamer-sections.txt	6 Nov 2006 15:14:46 -0000	1.279
+++ docs/gst/gstreamer-sections.txt	31 Dec 2006 13:54:20 -0000
@@ -29,6 +29,7 @@ gst_segtrap_is_enabled
 gst_segtrap_set_enabled
 gst_registry_fork_is_enabled
 gst_registry_fork_set_enabled
+gst_update_registry
 <SUBSECTION Private>
 GST_QUARK
 GstQuarkId
Index: tests/check/Makefile.am
===================================================================
RCS file: /cvs/gstreamer/gstreamer/tests/check/Makefile.am,v
retrieving revision 1.113
diff -u -p -r1.113 Makefile.am
--- tests/check/Makefile.am	21 Dec 2006 15:54:06 -0000	1.113
+++ tests/check/Makefile.am	31 Dec 2006 13:54:20 -0000
@@ -50,6 +50,7 @@ REGISTRY_CHECKS =				\
 	gst/gstghostpad				\
 	gst/gstplugin				\
 	gst/gstquery				\
+	gst/gstregistry				\
 	gst/gstutils				\
 	generic/sinks				\
 	elements/fakesink			\
Index: tests/check/gst/.cvsignore
===================================================================
RCS file: /cvs/gstreamer/gstreamer/tests/check/gst/.cvsignore,v
retrieving revision 1.17
diff -u -p -r1.17 .cvsignore
--- tests/check/gst/.cvsignore	29 Aug 2006 10:49:03 -0000	1.17
+++ tests/check/gst/.cvsignore	31 Dec 2006 13:54:20 -0000
@@ -16,6 +16,7 @@ gstobject
 gstpad
 gstpipeline
 gstplugin
+gstregistry
 gstsegment
 gststructure
 gstsystemclock
--- /dev/null	2006-12-24 14:33:46.000000000 +0000
+++ tests/check/gst/gstregistry.c	2006-12-25 12:26:01.000000000 +0000
@@ -0,0 +1,150 @@
+/* GStreamer unit tests for the plugin registry
+ *
+ * Copyright (C) 2006 Tim-Philipp Müller <tim centricular net>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <gst/check/gstcheck.h>
+#include <string.h>
+
+static gint
+plugin_name_cmp (GstPlugin * a, GstPlugin * b)
+{
+  const gchar *name_a = gst_plugin_get_name (a);
+  const gchar *name_b = gst_plugin_get_name (b);
+
+  return strcmp (name_a, name_b);
+}
+
+
+GST_START_TEST (test_registry_update)
+{
+  GstRegistry *registry;
+  GList *plugins_before, *plugins_after, *l;
+
+  registry = gst_registry_get_default ();
+  fail_unless (registry != NULL);
+  ASSERT_OBJECT_REFCOUNT (registry, "default registry", 1);
+
+  /* refcount should still be 1 the second time */
+  registry = gst_registry_get_default ();
+  fail_unless (registry != NULL);
+  ASSERT_OBJECT_REFCOUNT (registry, "default registry", 1);
+
+  /* plugins should have a refcount of 2: the registry holds one reference,
+   * and the other one is ours for the list */
+  plugins_before = gst_registry_get_plugin_list (registry);
+  for (l = plugins_before; l; l = l->next) {
+    GstPlugin *plugin;
+
+    plugin = GST_PLUGIN (l->data);
+    GST_LOG ("before1: plugin %p %d %s", plugin, GST_OBJECT_REFCOUNT (plugin),
+        gst_plugin_get_name (GST_PLUGIN (plugin)));
+    ASSERT_OBJECT_REFCOUNT (plugin, "plugin", 2);
+  }
+
+  fail_unless (gst_update_registry () != FALSE, "registry update failed");
+
+  GST_LOG (" ");
+
+  /* static plugins should have the same refcount as before (ie. 2), whereas
+   * file-based plugins should have been replaced by a newly-created objects
+   * (when reading the updated registry.xml file), so there should be only one
+   * reference left for those, and that's ours */
+  for (l = plugins_before; l; l = l->next) {
+    GstPlugin *plugin;
+
+    plugin = GST_PLUGIN (l->data);
+    GST_LOG ("before2: plugin %p %d %s", plugin, GST_OBJECT_REFCOUNT (plugin),
+        gst_plugin_get_name (GST_PLUGIN (plugin)));
+    if (gst_plugin_get_filename (plugin)) {
+      /* file-based plugin */
+      ASSERT_OBJECT_REFCOUNT (plugin, "plugin", 1);
+    } else {
+      /* static plugin */
+      ASSERT_OBJECT_REFCOUNT (plugin, "plugin", 2);
+    }
+  }
+
+  GST_LOG (" ");
+
+  plugins_after = gst_registry_get_plugin_list (registry);
+  for (l = plugins_after; l; l = l->next) {
+    GstPlugin *plugin;
+
+    plugin = GST_PLUGIN (l->data);
+    GST_LOG ("after  : plugin %p %d %s", plugin, GST_OBJECT_REFCOUNT (plugin),
+        gst_plugin_get_name (plugin));
+
+    /* file-based plugins should have a refcount of 2 (one for the registry,
+     * one for us for the list), static plugins should have one of 3 (one for
+     * the registry, one for the new list and one for the old list) */
+    if (gst_plugin_get_filename (plugin)) {
+      ASSERT_OBJECT_REFCOUNT (plugin, "plugin", 2);
+    } else {
+      ASSERT_OBJECT_REFCOUNT (plugin, "plugin", 3);
+    }
+  }
+
+  /* check that we still have all plugins in the new list that we had before */
+  for (l = plugins_after; l; l = l->next) {
+    GstPlugin *plugin;
+
+    plugin = GST_PLUGIN (l->data);
+
+    fail_unless (g_list_find_custom (plugins_before, plugin,
+        (GCompareFunc) plugin_name_cmp) != NULL,
+        "Plugin %s is in new list but not in old one?!",
+        gst_plugin_get_name (plugin));
+  }
+  for (l = plugins_before; l; l = l->next) {
+    GstPlugin *plugin;
+
+    plugin = GST_PLUGIN (l->data);
+    fail_unless (g_list_find_custom (plugins_after, plugin,
+        (GCompareFunc) plugin_name_cmp) != NULL,
+        "Plugin %s is in old list but not in new one?!",
+        gst_plugin_get_name (plugin));
+  }
+
+  gst_plugin_list_free (plugins_before);
+  plugins_before = NULL;
+  gst_plugin_list_free (plugins_after);
+  plugins_after = NULL;
+  registry = NULL;
+}
+
+GST_END_TEST;
+
+static Suite *
+registry_suite (void)
+{
+  Suite *s = suite_create ("registry");
+  TCase *tc_chain = tcase_create ("general");
+
+  suite_add_tcase (s, tc_chain);
+
+  tcase_add_test (tc_chain, test_registry_update);
+
+  return s;
+}
+
+GST_CHECK_MAIN (registry);
