core: Copy the factory list before creating devices
authorZeeshan Ali (Khattak) <zeeshanak@gnome.org>
Thu, 30 Jul 2009 14:37:32 +0000 (17:37 +0300)
committerZeeshan Ali (Khattak) <zeeshanak@gnome.org>
Thu, 30 Jul 2009 14:37:32 +0000 (17:37 +0300)
We iterate over the copy of the list rather than list itself because
there is high chances of the original list being modified during the
iteration, which is not allowed by libgee.

src/rygel/rygel-main.vala

index 8c95b3c..4f9ba0d 100644 (file)
@@ -73,7 +73,15 @@ public class Rygel.Main : Object {
 
     private void on_plugin_loaded (PluginLoader plugin_loader,
                                    Plugin       plugin) {
+        // We iterate over the copy of the list rather than list itself because
+        // there is high chances of the original list being modified during the
+        // iteration, which is not allowed by libgee.
+        var factories = new ArrayList <RootDeviceFactory> ();
         foreach (var factory in this.factories) {
+            factories.add (factory);
+        }
+
+        foreach (var factory in factories) {
             this.create_device (plugin, factory);
         }
     }
@@ -109,6 +117,7 @@ public class Rygel.Main : Object {
             var factory = new RootDeviceFactory (context);
             this.factories.add (factory);
 
+            // See the comment in on_plugin_loaded method
             var plugins = new ArrayList <Plugin> ();
             foreach (var plugin in this.plugin_loader.list_plugins ()) {
                 plugins.add (plugin);