printers: Replace explicit g_variant_unref calls with g_autoptr

This commit is contained in:
Robert Ancell 2019-11-21 21:52:09 +13:00 committed by Robert Ancell
parent 3a7533da1b
commit 815db8f404
4 changed files with 18 additions and 35 deletions

View file

@ -136,19 +136,21 @@ execute_action (CcPrintersPanel *self,
PpPrinterEntry *printer_entry; PpPrinterEntry *printer_entry;
const gchar *action_name; const gchar *action_name;
const gchar *printer_name; const gchar *printer_name;
GVariant *variant;
GVariant *action_variant;
gint count; gint count;
count = g_variant_n_children (action); count = g_variant_n_children (action);
if (count == 2) if (count == 2)
{ {
g_autoptr(GVariant) action_variant = NULL;
g_variant_get_child (action, 0, "v", &action_variant); g_variant_get_child (action, 0, "v", &action_variant);
action_name = g_variant_get_string (action_variant, NULL); action_name = g_variant_get_string (action_variant, NULL);
/* authenticate-jobs printer-name */ /* authenticate-jobs printer-name */
if (g_strcmp0 (action_name, "authenticate-jobs") == 0) if (g_strcmp0 (action_name, "authenticate-jobs") == 0)
{ {
g_autoptr(GVariant) variant = NULL;
g_variant_get_child (action, 1, "v", &variant); g_variant_get_child (action, 1, "v", &variant);
printer_name = g_variant_get_string (variant, NULL); printer_name = g_variant_get_string (variant, NULL);
@ -157,12 +159,12 @@ execute_action (CcPrintersPanel *self,
pp_printer_entry_authenticate_jobs (printer_entry); pp_printer_entry_authenticate_jobs (printer_entry);
else else
g_warning ("Could not find printer \"%s\"!", printer_name); g_warning ("Could not find printer \"%s\"!", printer_name);
g_variant_unref (variant);
} }
/* show-jobs printer-name */ /* show-jobs printer-name */
else if (g_strcmp0 (action_name, "show-jobs") == 0) else if (g_strcmp0 (action_name, "show-jobs") == 0)
{ {
g_autoptr(GVariant) variant = NULL;
g_variant_get_child (action, 1, "v", &variant); g_variant_get_child (action, 1, "v", &variant);
printer_name = g_variant_get_string (variant, NULL); printer_name = g_variant_get_string (variant, NULL);
@ -171,11 +173,7 @@ execute_action (CcPrintersPanel *self,
pp_printer_entry_show_jobs_dialog (printer_entry); pp_printer_entry_show_jobs_dialog (printer_entry);
else else
g_warning ("Could not find printer \"%s\"!", printer_name); g_warning ("Could not find printer \"%s\"!", printer_name);
g_variant_unref (variant);
} }
g_variant_unref (action_variant);
} }
} }
@ -336,9 +334,7 @@ on_get_job_attributes_cb (GObject *source_object,
CcPrintersPanel *self = (CcPrintersPanel*) user_data; CcPrintersPanel *self = (CcPrintersPanel*) user_data;
const gchar *job_originating_user_name; const gchar *job_originating_user_name;
const gchar *job_printer_uri; const gchar *job_printer_uri;
GVariant *attributes; g_autoptr(GVariant) attributes = NULL;
GVariant *username;
GVariant *printer_uri;
g_autoptr(GError) error = NULL; g_autoptr(GError) error = NULL;
attributes = pp_job_get_attributes_finish (PP_JOB (source_object), res, &error); attributes = pp_job_get_attributes_finish (PP_JOB (source_object), res, &error);
@ -346,8 +342,12 @@ on_get_job_attributes_cb (GObject *source_object,
if (attributes != NULL) if (attributes != NULL)
{ {
g_autoptr(GVariant) username = NULL;
if ((username = g_variant_lookup_value (attributes, "job-originating-user-name", G_VARIANT_TYPE ("as"))) != NULL) if ((username = g_variant_lookup_value (attributes, "job-originating-user-name", G_VARIANT_TYPE ("as"))) != NULL)
{ {
g_autoptr(GVariant) printer_uri = NULL;
if ((printer_uri = g_variant_lookup_value (attributes, "job-printer-uri", G_VARIANT_TYPE ("as"))) != NULL) if ((printer_uri = g_variant_lookup_value (attributes, "job-printer-uri", G_VARIANT_TYPE ("as"))) != NULL)
{ {
job_originating_user_name = g_variant_get_string (g_variant_get_child_value (username, 0), NULL); job_originating_user_name = g_variant_get_string (g_variant_get_child_value (username, 0), NULL);
@ -366,14 +366,8 @@ on_get_job_attributes_cb (GObject *source_object,
pp_printer_entry_update_jobs_count (printer_entry); pp_printer_entry_update_jobs_count (printer_entry);
} }
g_variant_unref (printer_uri);
} }
g_variant_unref (username);
} }
g_variant_unref (attributes);
} }
} }

View file

@ -907,7 +907,7 @@ group_physical_devices_dbus_cb (GObject *source_object,
if (output) if (output)
{ {
GVariant *array; g_autoptr(GVariant) array = NULL;
g_variant_get (output, "(@aas)", &array); g_variant_get (output, "(@aas)", &array);
@ -924,8 +924,6 @@ group_physical_devices_dbus_cb (GObject *source_object,
result[i] = device_uris; result[i] = device_uris;
i++; i++;
} }
g_variant_unref (array);
} }
} }
else if (error && else if (error &&

View file

@ -466,7 +466,6 @@ printer_add_real_async (PpNewPrinter *self)
static PPDName * static PPDName *
get_ppd_item_from_output (GVariant *output) get_ppd_item_from_output (GVariant *output)
{ {
GVariant *array;
PPDName *ppd_item = NULL; PPDName *ppd_item = NULL;
gint j; gint j;
static const char * const match_levels[] = { static const char * const match_levels[] = {
@ -478,6 +477,8 @@ get_ppd_item_from_output (GVariant *output)
if (output) if (output)
{ {
g_autoptr(GVariant) array = NULL;
g_variant_get (output, "(@a(ss))", &array); g_variant_get (output, "(@a(ss))", &array);
if (array) if (array)
{ {
@ -507,8 +508,6 @@ get_ppd_item_from_output (GVariant *output)
} }
} }
} }
g_variant_unref (array);
} }
} }
@ -1007,7 +1006,7 @@ get_missing_executables_cb (GObject *source_object,
if (output) if (output)
{ {
GVariant *array; g_autoptr(GVariant) array = NULL;
g_variant_get (output, "(@as)", &array); g_variant_get (output, "(@as)", &array);
@ -1019,8 +1018,6 @@ get_missing_executables_cb (GObject *source_object,
g_variant_get (array, "as", &iter); g_variant_get (array, "as", &iter);
while (g_variant_iter_next (iter, "&s", &executable)) while (g_variant_iter_next (iter, "&s", &executable))
executables = g_list_append (executables, g_strdup (executable)); executables = g_list_append (executables, g_strdup (executable));
g_variant_unref (array);
} }
} }
else if (error->domain == G_DBUS_ERROR && else if (error->domain == G_DBUS_ERROR &&

View file

@ -1905,7 +1905,7 @@ get_ppd_names_async_dbus_scb (GObject *source_object,
if (output) if (output)
{ {
GVariant *array; g_autoptr(GVariant) array = NULL;
g_variant_get (output, "(@a(ss))", g_variant_get (output, "(@a(ss))",
&array); &array);
@ -1945,8 +1945,6 @@ get_ppd_names_async_dbus_scb (GObject *source_object,
} }
} }
} }
g_variant_unref (array);
} }
} }
else else
@ -2125,7 +2123,7 @@ get_device_attributes_async_dbus_cb (GObject *source_object,
if (output) if (output)
{ {
const gchar *ret_error; const gchar *ret_error;
GVariant *devices_variant = NULL; g_autoptr(GVariant) devices_variant = NULL;
g_variant_get (output, "(&s@a{ss})", g_variant_get (output, "(&s@a{ss})",
&ret_error, &ret_error,
@ -2189,8 +2187,6 @@ get_device_attributes_async_dbus_cb (GObject *source_object,
} }
} }
} }
g_variant_unref (devices_variant);
} }
} }
else else
@ -3263,7 +3259,7 @@ get_cups_devices_async_dbus_cb (GObject *source_object,
if (output) if (output)
{ {
const gchar *ret_error; const gchar *ret_error;
GVariant *devices_variant = NULL; g_autoptr(GVariant) devices_variant = NULL;
gboolean is_network_device; gboolean is_network_device;
g_variant_get (output, "(&s@a{ss})", g_variant_get (output, "(&s@a{ss})",
@ -3335,8 +3331,6 @@ get_cups_devices_async_dbus_cb (GObject *source_object,
g_free (devices); g_free (devices);
} }
g_variant_unref (devices_variant);
} }
} }
else else