Plug mem leaks in gdbus tests & examples

Use "&s" instead of "s", and free the variant iters after use.

Bug #618663.
This commit is contained in:
Christian Persch 2010-05-14 20:07:15 +02:00
parent 60c53fef47
commit 661e5ea69f
9 changed files with 22 additions and 34 deletions

View File

@ -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);

View File

@ -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;

View File

@ -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)
{

View File

@ -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,

View File

@ -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)

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);