gdbus-auth: Fix leaks in tests
[platform/upstream/glib.git] / gio / tests / gdbus-example-peer.c
index a1041d9..b954f74 100644 (file)
@@ -1,17 +1,4 @@
 /*
- * Copyright © 2010 Red Hat, Inc.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published
- * by the Free Software Foundation; either version 2 of the licence or (at
- * your option) any later version.
- *
- * See the included COPYING file for more information.
- *
- * Author: David Zeuthen <davidz@redhat.com>
- */
-
-/*
 
 Usage examples (modulo addresses / credentials).
 
@@ -116,7 +103,7 @@ handle_method_call (GDBusConnection       *connection,
       const gchar *greeting;
       gchar *response;
 
-      g_variant_get (parameters, "(s)", &greeting);
+      g_variant_get (parameters, "(&s)", &greeting);
       response = g_strdup_printf ("You said '%s'. KTHXBYE!", greeting);
       g_dbus_method_invocation_return_value (invocation,
                                              g_variant_new ("(s)", response));
@@ -134,7 +121,7 @@ static const GDBusInterfaceVTable interface_vtable =
 
 /* ---------------------------------------------------------------------------------------------------- */
 
-static void
+static gboolean
 on_new_connection (GDBusServer *server,
                    GDBusConnection *connection,
                    gpointer user_data)
@@ -159,13 +146,14 @@ on_new_connection (GDBusServer *server,
   g_object_ref (connection);
   registration_id = g_dbus_connection_register_object (connection,
                                                        "/org/gtk/GDBus/TestObject",
-                                                       "org.gtk.GDBus.TestPeerInterface",
                                                        introspection_data->interfaces[0],
                                                        &interface_vtable,
                                                        NULL,  /* user_data */
                                                        NULL,  /* user_data_free_func */
                                                        NULL); /* GError** */
   g_assert (registration_id > 0);
+
+  return TRUE;
 }
 
 /* ---------------------------------------------------------------------------------------------------- */
@@ -189,8 +177,6 @@ main (int argc, char *argv[])
 
   ret = 1;
 
-  g_type_init ();
-
   opt_address = NULL;
   opt_server = FALSE;
   opt_allow_anonymous = FALSE;
@@ -273,6 +259,7 @@ main (int argc, char *argv[])
       error = NULL;
       connection = g_dbus_connection_new_for_address_sync (opt_address,
                                                            G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT,
+                                                           NULL, /* GDBusAuthObserver */
                                                            NULL, /* GCancellable */
                                                            &error);
       if (connection == NULL)
@@ -287,23 +274,24 @@ main (int argc, char *argv[])
                g_dbus_connection_get_capabilities (connection) & G_DBUS_CAPABILITY_FLAGS_UNIX_FD_PASSING);
 
       greeting = g_strdup_printf ("Hey, it's %" G_GUINT64_FORMAT " already!", (guint64) time (NULL));
-      value = g_dbus_connection_invoke_method_sync (connection,
-                                                    NULL, /* bus_name */
-                                                    "/org/gtk/GDBus/TestObject",
-                                                    "org.gtk.GDBus.TestPeerInterface",
-                                                    "HelloWorld",
-                                                    g_variant_new ("(s)", greeting),
-                                                    G_DBUS_INVOKE_METHOD_FLAGS_NONE,
-                                                    -1,
-                                                    NULL,
-                                                    &error);
+      value = g_dbus_connection_call_sync (connection,
+                                           NULL, /* bus_name */
+                                           "/org/gtk/GDBus/TestObject",
+                                           "org.gtk.GDBus.TestPeerInterface",
+                                           "HelloWorld",
+                                           g_variant_new ("(s)", greeting),
+                                           G_VARIANT_TYPE ("(s)"),
+                                           G_DBUS_CALL_FLAGS_NONE,
+                                           -1,
+                                           NULL,
+                                           &error);
       if (value == NULL)
         {
           g_printerr ("Error invoking HelloWorld(): %s\n", error->message);
           g_error_free (error);
           goto out;
         }
-      g_variant_get (value, "(s)", &greeting_response);
+      g_variant_get (value, "(&s)", &greeting_response);
       g_print ("Server said: %s\n", greeting_response);
       g_variant_unref (value);