[Telepathy-commits] [telepathy-glib/master] inspect-contact example: use tp_dbus_daemon_dup and fix cleanup code

Simon McVittie simon.mcvittie at collabora.co.uk
Fri Jan 30 07:14:03 PST 2009


---
 examples/client/inspect-contact.c |   48 +++++++++++++++++++++---------------
 1 files changed, 28 insertions(+), 20 deletions(-)

diff --git a/examples/client/inspect-contact.c b/examples/client/inspect-contact.c
index 33941b3..8743bba 100644
--- a/examples/client/inspect-contact.c
+++ b/examples/client/inspect-contact.c
@@ -117,15 +117,16 @@ main (int argc,
       char **argv)
 {
   const gchar *bus_name, *object_path;
-  TpConnection *connection;
-  GMainLoop *mainloop;
-  TpDBusDaemon *daemon;
+  TpConnection *connection = NULL;
+  GMainLoop *mainloop = NULL;
+  TpDBusDaemon *daemon = NULL;
   GError *error = NULL;
   static TpContactFeature features[] = {
       TP_CONTACT_FEATURE_ALIAS,
       TP_CONTACT_FEATURE_AVATAR_TOKEN,
       TP_CONTACT_FEATURE_PRESENCE
   };
+  int ret = 1;
 
   g_type_init ();
   tp_debug_set_flags (g_getenv ("EXAMPLE_DEBUG"));
@@ -152,20 +153,21 @@ main (int argc,
       bus_name = argv[1];
     }
 
-  daemon = tp_dbus_daemon_new (tp_get_bus ());
+  daemon = tp_dbus_daemon_dup (&error);
+
+  if (daemon == NULL)
+    {
+      g_warning ("%s", error->message);
+      goto out;
+    }
+
   connection = tp_connection_new (daemon, bus_name, object_path, &error);
 
   if (connection == NULL ||
       !tp_connection_run_until_ready (connection, FALSE, &error, NULL))
     {
       g_warning ("%s", error->message);
-      g_error_free (error);
-      g_object_unref (daemon);
-
-      if (connection != NULL)
-        g_object_unref (connection);
-
-      return 1;
+      goto out;
     }
 
   g_message ("Connection ready\n");
@@ -180,11 +182,7 @@ main (int argc,
             &self_handle, &error, NULL))
         {
           g_warning ("%s", error->message);
-          g_error_free (error);
-          g_main_loop_unref (mainloop);
-          g_object_unref (connection);
-          g_object_unref (daemon);
-          return 1;
+          goto out;
         }
 
       tp_connection_get_contacts_by_handle (connection,
@@ -207,10 +205,20 @@ main (int argc,
     }
 
   g_main_loop_run (mainloop);
+  ret = 0;
+
+out:
+  if (error != NULL)
+    g_error_free (error);
+
+  if (mainloop != NULL)
+    g_main_loop_unref (mainloop);
+
+  if (connection != NULL)
+    g_object_unref (connection);
 
-  g_main_loop_unref (mainloop);
-  g_object_unref (connection);
-  g_object_unref (daemon);
+  if (daemon != NULL)
+    g_object_unref (daemon);
 
-  return 0;
+  return ret;
 }
-- 
1.5.6.5




More information about the telepathy-commits mailing list