[gnome-control-center] sharing: Use g_variant_get_{string|variant}() instead of g_variant_get()
- From: Mario Sanchez Prada <msanchez src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center] sharing: Use g_variant_get_{string|variant}() instead of g_variant_get()
- Date: Mon, 27 Apr 2015 14:57:00 +0000 (UTC)
commit fd7d7d4c108056aefc63ee490be54bcb734de04f
Author: Mario Sanchez Prada <mario endlessm com>
Date: Mon Apr 27 11:38:44 2015 +0100
sharing: Use g_variant_get_{string|variant}() instead of g_variant_get()
Besides being a better practice, this changes also fixes 2 memory leaks
when handling strings boxed inside GVariant objects.
https://bugzilla.gnome.org/show_bug.cgi?id=748411
panels/sharing/cc-remote-login.c | 22 ++++++++++++++--------
1 files changed, 14 insertions(+), 8 deletions(-)
---
diff --git a/panels/sharing/cc-remote-login.c b/panels/sharing/cc-remote-login.c
index aedef9c..b9de0b3 100644
--- a/panels/sharing/cc-remote-login.c
+++ b/panels/sharing/cc-remote-login.c
@@ -48,7 +48,7 @@ active_state_ready_callback (GObject *source_object,
GAsyncResult *result,
CallbackData *callback_data)
{
- GVariant *active_variant, *tmp_variant;
+ GVariant *active_variant, *child_variant, *tmp_variant;
const gchar *active_state;
gboolean active;
GError *error = NULL;
@@ -71,13 +71,15 @@ active_state_ready_callback (GObject *source_object,
return;
}
- g_variant_get (active_variant, "(v)", &tmp_variant);
+ child_variant = g_variant_get_child_value (active_variant, 0);
+ tmp_variant = g_variant_get_variant (child_variant);
active_state = g_variant_get_string (tmp_variant, NULL);
active = g_str_equal (active_state, "active");
- g_variant_unref (active_variant);
g_variant_unref (tmp_variant);
+ g_variant_unref (child_variant);
+ g_variant_unref (active_variant);
/* set the switch to the correct state */
if (callback_data->gtkswitch)
@@ -91,8 +93,8 @@ path_ready_callback (GObject *source_object,
GAsyncResult *result,
CallbackData *callback_data)
{
- GVariant *path_variant;
- gchar *object_path;
+ GVariant *path_variant, *child_variant;
+ const gchar *object_path;
GError *error = NULL;
path_variant = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source_object),
@@ -122,7 +124,8 @@ path_ready_callback (GObject *source_object,
return;
}
- g_variant_get (path_variant, "(o)", &object_path);
+ child_variant = g_variant_get_child_value (path_variant, 0);
+ object_path = g_variant_get_string (child_variant, NULL);
g_dbus_connection_call (G_DBUS_CONNECTION (source_object),
"org.freedesktop.systemd1",
@@ -139,6 +142,7 @@ path_ready_callback (GObject *source_object,
(GAsyncReadyCallback) active_state_ready_callback,
callback_data);
+ g_variant_unref (child_variant);
g_variant_unref (path_variant);
}
@@ -147,7 +151,7 @@ state_ready_callback (GObject *source_object,
GAsyncResult *result,
CallbackData *callback_data)
{
- GVariant *state_variant;
+ GVariant *state_variant, *child_variant;
const gchar *state_string;
GError *error = NULL;
@@ -177,7 +181,8 @@ state_ready_callback (GObject *source_object,
return;
}
- g_variant_get (state_variant, "(s)", &state_string);
+ child_variant = g_variant_get_child_value (state_variant, 0);
+ state_string = g_variant_get_string (child_variant, NULL);
if (g_str_equal (state_string, "enabled"))
{
@@ -210,6 +215,7 @@ state_ready_callback (GObject *source_object,
g_free (callback_data);
}
+ g_variant_unref (child_variant);
g_variant_unref (state_variant);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]