From 661e5ea69f2d370af6e4e9c73242cf158414dd5d Mon Sep 17 00:00:00 2001 From: Christian Persch Date: Fri, 14 May 2010 20:07:15 +0200 Subject: [PATCH] Plug mem leaks in gdbus tests & examples Use "&s" instead of "s", and free the variant iters after use. Bug #618663. --- gio/tests/gdbus-example-peer.c | 4 ++-- gio/tests/gdbus-example-proxy-subclass.c | 12 +++--------- gio/tests/gdbus-example-server.c | 2 +- gio/tests/gdbus-example-subtree.c | 6 +++--- gio/tests/gdbus-example-watch-proxy.c | 12 ++++-------- gio/tests/gdbus-export.c | 8 +++----- gio/tests/gdbus-introspection.c | 2 +- gio/tests/gdbus-peer.c | 8 ++++---- gio/tests/gdbus-proxy.c | 2 +- 9 files changed, 22 insertions(+), 34 deletions(-) diff --git a/gio/tests/gdbus-example-peer.c b/gio/tests/gdbus-example-peer.c index 649b047..316680e 100644 --- a/gio/tests/gdbus-example-peer.c +++ b/gio/tests/gdbus-example-peer.c @@ -103,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)); @@ -290,7 +290,7 @@ main (int argc, char *argv[]) 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); diff --git a/gio/tests/gdbus-example-proxy-subclass.c b/gio/tests/gdbus-example-proxy-subclass.c index 19e313c..b5ee9f8 100644 --- a/gio/tests/gdbus-example-proxy-subclass.c +++ b/gio/tests/gdbus-example-proxy-subclass.c @@ -208,18 +208,13 @@ accounts_user_g_properties_changed (GDBusProxy *proxy, { AccountsUser *user = ACCOUNTS_USER (proxy); GVariantIter *iter; - GVariant *item; + const gchar *key; if (changed_properties != NULL) { g_variant_get (changed_properties, "a{sv}", &iter); - while ((item = g_variant_iter_next_value (iter)) != NULL) + while (g_variant_iter_next (iter, "{&sv}", &key, NULL)) { - const gchar *key; - g_variant_get (item, - "{sv}", - &key, - NULL); if (g_strcmp0 (key, "AutomaticLogin") == 0) g_object_notify (G_OBJECT (user), "automatic-login"); else if (g_strcmp0 (key, "RealName") == 0) @@ -227,6 +222,7 @@ accounts_user_g_properties_changed (GDBusProxy *proxy, else if (g_strcmp0 (key, "UserName") == 0) g_object_notify (G_OBJECT (user), "user-name"); } + g_variant_iter_free (iter); } } @@ -308,7 +304,6 @@ accounts_user_frobnicate_sync (AccountsUser *user, if (value != NULL) { g_variant_get (value, "(s)", &ret); - ret = g_strdup (ret); g_variant_unref (value); } return ret; @@ -349,7 +344,6 @@ accounts_user_frobnicate_finish (AccountsUser *user, if (value != NULL) { g_variant_get (value, "(s)", &ret); - ret = g_strdup (ret); g_variant_unref (value); } return ret; diff --git a/gio/tests/gdbus-example-server.c b/gio/tests/gdbus-example-server.c index 93dd53a..2c58a24 100644 --- a/gio/tests/gdbus-example-server.c +++ b/gio/tests/gdbus-example-server.c @@ -64,7 +64,7 @@ handle_method_call (GDBusConnection *connection, { const gchar *greeting; - g_variant_get (parameters, "(s)", &greeting); + g_variant_get (parameters, "(&s)", &greeting); if (g_strcmp0 (greeting, "Return Unregistered") == 0) { diff --git a/gio/tests/gdbus-example-subtree.c b/gio/tests/gdbus-example-subtree.c index 1633acc..b037dd3 100644 --- a/gio/tests/gdbus-example-subtree.c +++ b/gio/tests/gdbus-example-subtree.c @@ -55,7 +55,7 @@ manager_method_call (GDBusConnection *connection, g_assert_cmpstr (interface_name, ==, "org.gtk.GDBus.Example.Manager"); g_assert_cmpstr (method_name, ==, "Hello"); - g_variant_get (parameters, "(s)", &greeting); + g_variant_get (parameters, "(&s)", &greeting); response = g_strdup_printf ("Method %s.%s with user_data `%s' on object path %s called with arg '%s'", interface_name, @@ -94,7 +94,7 @@ block_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 ("Method %s.%s with user_data `%s' on object path %s called with arg '%s'", interface_name, @@ -207,7 +207,7 @@ partition_method_call (GDBusConnection *connection, g_assert_cmpstr (interface_name, ==, "org.gtk.GDBus.Example.Partition"); g_assert_cmpstr (method_name, ==, "Hello"); - g_variant_get (parameters, "(s)", &greeting); + g_variant_get (parameters, "(&s)", &greeting); response = g_strdup_printf ("Method %s.%s with user_data `%s' on object path %s called with arg '%s'", interface_name, diff --git a/gio/tests/gdbus-example-watch-proxy.c b/gio/tests/gdbus-example-watch-proxy.c index 4f4195f..e5b844d 100644 --- a/gio/tests/gdbus-example-watch-proxy.c +++ b/gio/tests/gdbus-example-watch-proxy.c @@ -54,25 +54,21 @@ on_properties_changed (GDBusProxy *proxy, if (g_variant_n_children (changed_properties) > 0) { GVariantIter *iter; - GVariant *item; + const gchar *key; + GVariant *value; g_print (" *** Properties Changed:\n"); g_variant_get (changed_properties, "a{sv}", &iter); - while ((item = g_variant_iter_next_value (iter))) + while (g_variant_iter_loop (iter, "{&sv}", &key, &value)) { - const gchar *key; - GVariant *value; gchar *value_str; - g_variant_get (item, - "{sv}", - &key, - &value); value_str = g_variant_print (value, TRUE); g_print (" %s -> %s\n", key, value_str); g_free (value_str); } + g_variant_iter_free (iter); } if (g_strv_length ((GStrv) invalidated_properties) > 0) diff --git a/gio/tests/gdbus-export.c b/gio/tests/gdbus-export.c index ff6cc28..3041527 100644 --- a/gio/tests/gdbus-export.c +++ b/gio/tests/gdbus-export.c @@ -136,7 +136,7 @@ foo_method_call (GDBusConnection *connection, { const gchar *input; gchar *output; - g_variant_get (parameters, "(s)", &input); + g_variant_get (parameters, "(&s)", &input); output = g_strdup_printf ("You passed the string `%s'. Jolly good!", input); g_dbus_method_invocation_return_value (invocation, g_variant_new ("(s)", output)); g_free (output); @@ -314,7 +314,6 @@ introspect_callback (GDBusProxy *proxy, GAsyncResult *res, gpointer user_data) { - const gchar *s; gchar **xml_data = user_data; GVariant *result; GError *error; @@ -325,8 +324,7 @@ introspect_callback (GDBusProxy *proxy, &error); g_assert_no_error (error); g_assert (result != NULL); - g_variant_get (result, "(s)", &s); - *xml_data = g_strdup (s); + g_variant_get (result, "(s)", xml_data); g_variant_unref (result); g_main_loop_quit (loop); @@ -783,7 +781,7 @@ test_dispatch_thread_func (gpointer user_data) g_assert_no_error (error); g_assert (value != NULL); g_assert (g_variant_is_of_type (value, G_VARIANT_TYPE ("(s)"))); - g_variant_get (value, "(s)", &value_str); + g_variant_get (value, "(&s)", &value_str); g_assert_cmpstr (value_str, ==, "You passed the string `winwinwin'. Jolly good!"); g_variant_unref (value); diff --git a/gio/tests/gdbus-introspection.c b/gio/tests/gdbus-introspection.c index e7fab2b..6209c5d 100644 --- a/gio/tests/gdbus-introspection.c +++ b/gio/tests/gdbus-introspection.c @@ -62,7 +62,7 @@ introspection_on_proxy_appeared (GDBusConnection *connection, &error); g_assert_no_error (error); g_assert (result != NULL); - g_variant_get (result, "(s)", &xml_data); + g_variant_get (result, "(&s)", &xml_data); node_info = g_dbus_node_info_new_for_xml (xml_data, &error); g_assert_no_error (error); diff --git a/gio/tests/gdbus-peer.c b/gio/tests/gdbus-peer.c index 929d5c2..abea948 100644 --- a/gio/tests/gdbus-peer.c +++ b/gio/tests/gdbus-peer.c @@ -101,7 +101,7 @@ test_interface_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 greeted me with '%s'.", greeting); @@ -132,7 +132,7 @@ test_interface_method_call (GDBusConnection *connection, gint fd; GUnixFDList *fd_list; - g_variant_get (parameters, "(s)", &path); + g_variant_get (parameters, "(&s)", &path); fd_list = g_unix_fd_list_new (); @@ -544,7 +544,7 @@ test_peer (void) NULL, /* GCancellable */ &error); g_assert_no_error (error); - g_variant_get (result, "(s)", &s); + g_variant_get (result, "(&s)", &s); g_assert_cmpstr (s, ==, "You greeted me with 'Hey Peer!'."); g_variant_unref (result); g_assert_cmpint (data.num_method_calls, ==, 1); @@ -688,7 +688,7 @@ test_peer (void) NULL, /* GCancellable */ &error); g_assert_no_error (error); - g_variant_get (result, "(s)", &s); + g_variant_get (result, "(&s)", &s); g_assert_cmpstr (s, ==, "You greeted me with 'Hey Again Peer!'."); g_variant_unref (result); g_assert_cmpint (data.num_method_calls, ==, 4); diff --git a/gio/tests/gdbus-proxy.c b/gio/tests/gdbus-proxy.c index 17752fe..970bf47 100644 --- a/gio/tests/gdbus-proxy.c +++ b/gio/tests/gdbus-proxy.c @@ -56,7 +56,7 @@ test_methods (GDBusConnection *connection, g_assert_no_error (error); g_assert (result != NULL); g_assert_cmpstr (g_variant_get_type_string (result), ==, "(s)"); - g_variant_get (result, "(s)", &str); + g_variant_get (result, "(&s)", &str); g_assert_cmpstr (str, ==, "You greeted me with 'Hey'. Thanks!"); g_variant_unref (result); -- 2.7.4