[Telepathy-commits] [telepathy-glib/master] inspect-connection example: use tp_dbus_daemon_dup and fix cleanup code
Simon McVittie
simon.mcvittie at collabora.co.uk
Fri Jan 30 07:13:51 PST 2009
---
examples/client/inspect-connection.c | 37 ++++++++++++++++++++++------------
1 files changed, 24 insertions(+), 13 deletions(-)
diff --git a/examples/client/inspect-connection.c b/examples/client/inspect-connection.c
index 5b961e2..3a6c1b5 100644
--- a/examples/client/inspect-connection.c
+++ b/examples/client/inspect-connection.c
@@ -57,10 +57,11 @@ 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;
+ int ret = 1;
g_type_init ();
tp_debug_set_flags (g_getenv ("EXAMPLE_DEBUG"));
@@ -87,7 +88,14 @@ main (int argc,
bus_name = NULL;
}
- daemon = tp_dbus_daemon_new (tp_get_bus ());
+ daemon = tp_dbus_daemon_dup (&error);
+
+ if (daemon == NULL)
+ {
+ g_warning ("%s", error->message);
+ g_error_free (error);
+ goto out;
+ }
connection = tp_connection_new (daemon, bus_name, object_path, &error);
@@ -100,12 +108,7 @@ main (int argc,
{
g_warning ("%s", error->message);
g_error_free (error);
- g_object_unref (daemon);
-
- if (connection != NULL)
- g_object_unref (connection);
-
- return 1;
+ goto out;
}
printf ("Connection ready\n");
@@ -117,9 +120,17 @@ main (int argc,
(GDestroyNotify) g_main_loop_unref, NULL);
g_main_loop_run (mainloop);
+ ret = 0;
+
+out:
+ if (connection != NULL)
+ g_object_unref (connection);
+
+ if (mainloop != NULL)
+ g_main_loop_unref (mainloop);
- g_main_loop_unref (mainloop);
- 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