[gvfs/gnome-3-14] proxy volume monitor: Properly handle failure to create a remote proxy



commit 1537cf7d31706019e603748c0d4f5626b7d9eae3
Author: Debarshi Ray <debarshir gnome org>
Date:   Fri Oct 16 13:35:34 2015 +0200

    proxy volume monitor: Properly handle failure to create a remote proxy
    
    We should finish constructing the innards of the object and not leave
    it in an inconsistent state when we hit an error. The other option
    would be to litter the rest of the code with NULL checks, but that
    would be ugly and prone to errors.
    
    We should also ensure that the reference counting stays consistent with
    the non-error paths.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=755805

 monitor/proxy/gproxyvolumemonitor.c |   15 ++++++---------
 1 files changed, 6 insertions(+), 9 deletions(-)
---
diff --git a/monitor/proxy/gproxyvolumemonitor.c b/monitor/proxy/gproxyvolumemonitor.c
index b05b8c7..2e9cc51 100644
--- a/monitor/proxy/gproxyvolumemonitor.c
+++ b/monitor/proxy/gproxyvolumemonitor.c
@@ -969,10 +969,7 @@ g_proxy_volume_monitor_constructor (GType                  type,
   klass = G_PROXY_VOLUME_MONITOR_CLASS (g_type_class_peek (type));
   object = g_hash_table_lookup (the_volume_monitors, (gpointer) type);
   if (object != NULL)
-    {
-      g_object_ref (object);
-      goto out;
-    }
+    goto out;
 
   dbus_name = klass->dbus_name;
 
@@ -985,6 +982,10 @@ g_proxy_volume_monitor_constructor (GType                  type,
 
   monitor = G_PROXY_VOLUME_MONITOR (object);
 
+  monitor->drives = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
+  monitor->volumes = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
+  monitor->mounts = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
+
   error = NULL;
   monitor->proxy = gvfs_remote_volume_monitor_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
                                                                       
G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES,
@@ -1019,10 +1020,6 @@ g_proxy_volume_monitor_constructor (GType                  type,
   g_signal_connect (monitor->proxy, "volume-changed", G_CALLBACK (volume_changed), monitor);
   g_signal_connect (monitor->proxy, "volume-removed", G_CALLBACK (volume_removed), monitor);
 
-  monitor->drives = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
-  monitor->volumes = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
-  monitor->mounts = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
-
   /* listen to when the owner of the service appears/disappears */
   g_signal_connect (monitor->proxy, "notify::g-name-owner", G_CALLBACK (name_owner_changed), monitor);
   /* initially seed drives/volumes/mounts if we have an owner */
@@ -1035,12 +1032,12 @@ g_proxy_volume_monitor_constructor (GType                  type,
 
   g_hash_table_insert (the_volume_monitors, (gpointer) type, object);
 
+ out:
   /* Take an extra reference to make the instance live forever - see also
    * the dispose() and finalize() vfuncs
    */
   g_object_ref (object);
 
- out:
   G_UNLOCK (proxy_vm);
   return object;
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]