mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-07 11:25:48 +01:00
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:
parent
60c53fef47
commit
661e5ea69f
@ -103,7 +103,7 @@ handle_method_call (GDBusConnection *connection,
|
|||||||
const gchar *greeting;
|
const gchar *greeting;
|
||||||
gchar *response;
|
gchar *response;
|
||||||
|
|
||||||
g_variant_get (parameters, "(s)", &greeting);
|
g_variant_get (parameters, "(&s)", &greeting);
|
||||||
response = g_strdup_printf ("You said '%s'. KTHXBYE!", greeting);
|
response = g_strdup_printf ("You said '%s'. KTHXBYE!", greeting);
|
||||||
g_dbus_method_invocation_return_value (invocation,
|
g_dbus_method_invocation_return_value (invocation,
|
||||||
g_variant_new ("(s)", response));
|
g_variant_new ("(s)", response));
|
||||||
@ -290,7 +290,7 @@ main (int argc, char *argv[])
|
|||||||
g_error_free (error);
|
g_error_free (error);
|
||||||
goto out;
|
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_print ("Server said: %s\n", greeting_response);
|
||||||
g_variant_unref (value);
|
g_variant_unref (value);
|
||||||
|
|
||||||
|
@ -208,18 +208,13 @@ accounts_user_g_properties_changed (GDBusProxy *proxy,
|
|||||||
{
|
{
|
||||||
AccountsUser *user = ACCOUNTS_USER (proxy);
|
AccountsUser *user = ACCOUNTS_USER (proxy);
|
||||||
GVariantIter *iter;
|
GVariantIter *iter;
|
||||||
GVariant *item;
|
const gchar *key;
|
||||||
|
|
||||||
if (changed_properties != NULL)
|
if (changed_properties != NULL)
|
||||||
{
|
{
|
||||||
g_variant_get (changed_properties, "a{sv}", &iter);
|
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)
|
if (g_strcmp0 (key, "AutomaticLogin") == 0)
|
||||||
g_object_notify (G_OBJECT (user), "automatic-login");
|
g_object_notify (G_OBJECT (user), "automatic-login");
|
||||||
else if (g_strcmp0 (key, "RealName") == 0)
|
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)
|
else if (g_strcmp0 (key, "UserName") == 0)
|
||||||
g_object_notify (G_OBJECT (user), "user-name");
|
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)
|
if (value != NULL)
|
||||||
{
|
{
|
||||||
g_variant_get (value, "(s)", &ret);
|
g_variant_get (value, "(s)", &ret);
|
||||||
ret = g_strdup (ret);
|
|
||||||
g_variant_unref (value);
|
g_variant_unref (value);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
@ -349,7 +344,6 @@ accounts_user_frobnicate_finish (AccountsUser *user,
|
|||||||
if (value != NULL)
|
if (value != NULL)
|
||||||
{
|
{
|
||||||
g_variant_get (value, "(s)", &ret);
|
g_variant_get (value, "(s)", &ret);
|
||||||
ret = g_strdup (ret);
|
|
||||||
g_variant_unref (value);
|
g_variant_unref (value);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -64,7 +64,7 @@ handle_method_call (GDBusConnection *connection,
|
|||||||
{
|
{
|
||||||
const gchar *greeting;
|
const gchar *greeting;
|
||||||
|
|
||||||
g_variant_get (parameters, "(s)", &greeting);
|
g_variant_get (parameters, "(&s)", &greeting);
|
||||||
|
|
||||||
if (g_strcmp0 (greeting, "Return Unregistered") == 0)
|
if (g_strcmp0 (greeting, "Return Unregistered") == 0)
|
||||||
{
|
{
|
||||||
|
@ -55,7 +55,7 @@ manager_method_call (GDBusConnection *connection,
|
|||||||
g_assert_cmpstr (interface_name, ==, "org.gtk.GDBus.Example.Manager");
|
g_assert_cmpstr (interface_name, ==, "org.gtk.GDBus.Example.Manager");
|
||||||
g_assert_cmpstr (method_name, ==, "Hello");
|
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'",
|
response = g_strdup_printf ("Method %s.%s with user_data `%s' on object path %s called with arg '%s'",
|
||||||
interface_name,
|
interface_name,
|
||||||
@ -94,7 +94,7 @@ block_method_call (GDBusConnection *connection,
|
|||||||
const gchar *greeting;
|
const gchar *greeting;
|
||||||
gchar *response;
|
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'",
|
response = g_strdup_printf ("Method %s.%s with user_data `%s' on object path %s called with arg '%s'",
|
||||||
interface_name,
|
interface_name,
|
||||||
@ -207,7 +207,7 @@ partition_method_call (GDBusConnection *connection,
|
|||||||
g_assert_cmpstr (interface_name, ==, "org.gtk.GDBus.Example.Partition");
|
g_assert_cmpstr (interface_name, ==, "org.gtk.GDBus.Example.Partition");
|
||||||
g_assert_cmpstr (method_name, ==, "Hello");
|
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'",
|
response = g_strdup_printf ("Method %s.%s with user_data `%s' on object path %s called with arg '%s'",
|
||||||
interface_name,
|
interface_name,
|
||||||
|
@ -54,25 +54,21 @@ on_properties_changed (GDBusProxy *proxy,
|
|||||||
if (g_variant_n_children (changed_properties) > 0)
|
if (g_variant_n_children (changed_properties) > 0)
|
||||||
{
|
{
|
||||||
GVariantIter *iter;
|
GVariantIter *iter;
|
||||||
GVariant *item;
|
const gchar *key;
|
||||||
|
GVariant *value;
|
||||||
|
|
||||||
g_print (" *** Properties Changed:\n");
|
g_print (" *** Properties Changed:\n");
|
||||||
g_variant_get (changed_properties,
|
g_variant_get (changed_properties,
|
||||||
"a{sv}",
|
"a{sv}",
|
||||||
&iter);
|
&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;
|
gchar *value_str;
|
||||||
g_variant_get (item,
|
|
||||||
"{sv}",
|
|
||||||
&key,
|
|
||||||
&value);
|
|
||||||
value_str = g_variant_print (value, TRUE);
|
value_str = g_variant_print (value, TRUE);
|
||||||
g_print (" %s -> %s\n", key, value_str);
|
g_print (" %s -> %s\n", key, value_str);
|
||||||
g_free (value_str);
|
g_free (value_str);
|
||||||
}
|
}
|
||||||
|
g_variant_iter_free (iter);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (g_strv_length ((GStrv) invalidated_properties) > 0)
|
if (g_strv_length ((GStrv) invalidated_properties) > 0)
|
||||||
|
@ -136,7 +136,7 @@ foo_method_call (GDBusConnection *connection,
|
|||||||
{
|
{
|
||||||
const gchar *input;
|
const gchar *input;
|
||||||
gchar *output;
|
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);
|
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_dbus_method_invocation_return_value (invocation, g_variant_new ("(s)", output));
|
||||||
g_free (output);
|
g_free (output);
|
||||||
@ -314,7 +314,6 @@ introspect_callback (GDBusProxy *proxy,
|
|||||||
GAsyncResult *res,
|
GAsyncResult *res,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
const gchar *s;
|
|
||||||
gchar **xml_data = user_data;
|
gchar **xml_data = user_data;
|
||||||
GVariant *result;
|
GVariant *result;
|
||||||
GError *error;
|
GError *error;
|
||||||
@ -325,8 +324,7 @@ introspect_callback (GDBusProxy *proxy,
|
|||||||
&error);
|
&error);
|
||||||
g_assert_no_error (error);
|
g_assert_no_error (error);
|
||||||
g_assert (result != NULL);
|
g_assert (result != NULL);
|
||||||
g_variant_get (result, "(s)", &s);
|
g_variant_get (result, "(s)", xml_data);
|
||||||
*xml_data = g_strdup (s);
|
|
||||||
g_variant_unref (result);
|
g_variant_unref (result);
|
||||||
|
|
||||||
g_main_loop_quit (loop);
|
g_main_loop_quit (loop);
|
||||||
@ -783,7 +781,7 @@ test_dispatch_thread_func (gpointer user_data)
|
|||||||
g_assert_no_error (error);
|
g_assert_no_error (error);
|
||||||
g_assert (value != NULL);
|
g_assert (value != NULL);
|
||||||
g_assert (g_variant_is_of_type (value, G_VARIANT_TYPE ("(s)")));
|
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_assert_cmpstr (value_str, ==, "You passed the string `winwinwin'. Jolly good!");
|
||||||
g_variant_unref (value);
|
g_variant_unref (value);
|
||||||
|
|
||||||
|
@ -62,7 +62,7 @@ introspection_on_proxy_appeared (GDBusConnection *connection,
|
|||||||
&error);
|
&error);
|
||||||
g_assert_no_error (error);
|
g_assert_no_error (error);
|
||||||
g_assert (result != NULL);
|
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);
|
node_info = g_dbus_node_info_new_for_xml (xml_data, &error);
|
||||||
g_assert_no_error (error);
|
g_assert_no_error (error);
|
||||||
|
@ -101,7 +101,7 @@ test_interface_method_call (GDBusConnection *connection,
|
|||||||
const gchar *greeting;
|
const gchar *greeting;
|
||||||
gchar *response;
|
gchar *response;
|
||||||
|
|
||||||
g_variant_get (parameters, "(s)", &greeting);
|
g_variant_get (parameters, "(&s)", &greeting);
|
||||||
|
|
||||||
response = g_strdup_printf ("You greeted me with '%s'.",
|
response = g_strdup_printf ("You greeted me with '%s'.",
|
||||||
greeting);
|
greeting);
|
||||||
@ -132,7 +132,7 @@ test_interface_method_call (GDBusConnection *connection,
|
|||||||
gint fd;
|
gint fd;
|
||||||
GUnixFDList *fd_list;
|
GUnixFDList *fd_list;
|
||||||
|
|
||||||
g_variant_get (parameters, "(s)", &path);
|
g_variant_get (parameters, "(&s)", &path);
|
||||||
|
|
||||||
fd_list = g_unix_fd_list_new ();
|
fd_list = g_unix_fd_list_new ();
|
||||||
|
|
||||||
@ -544,7 +544,7 @@ test_peer (void)
|
|||||||
NULL, /* GCancellable */
|
NULL, /* GCancellable */
|
||||||
&error);
|
&error);
|
||||||
g_assert_no_error (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_assert_cmpstr (s, ==, "You greeted me with 'Hey Peer!'.");
|
||||||
g_variant_unref (result);
|
g_variant_unref (result);
|
||||||
g_assert_cmpint (data.num_method_calls, ==, 1);
|
g_assert_cmpint (data.num_method_calls, ==, 1);
|
||||||
@ -688,7 +688,7 @@ test_peer (void)
|
|||||||
NULL, /* GCancellable */
|
NULL, /* GCancellable */
|
||||||
&error);
|
&error);
|
||||||
g_assert_no_error (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_assert_cmpstr (s, ==, "You greeted me with 'Hey Again Peer!'.");
|
||||||
g_variant_unref (result);
|
g_variant_unref (result);
|
||||||
g_assert_cmpint (data.num_method_calls, ==, 4);
|
g_assert_cmpint (data.num_method_calls, ==, 4);
|
||||||
|
@ -56,7 +56,7 @@ test_methods (GDBusConnection *connection,
|
|||||||
g_assert_no_error (error);
|
g_assert_no_error (error);
|
||||||
g_assert (result != NULL);
|
g_assert (result != NULL);
|
||||||
g_assert_cmpstr (g_variant_get_type_string (result), ==, "(s)");
|
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_assert_cmpstr (str, ==, "You greeted me with 'Hey'. Thanks!");
|
||||||
g_variant_unref (result);
|
g_variant_unref (result);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user