diff options
author | Robert Ancell <robert.ancell@canonical.com> | 2019-11-21 21:47:01 +1300 |
---|---|---|
committer | Robert Ancell <robert.ancell@gmail.com> | 2020-03-30 03:24:58 +0000 |
commit | 3a7533da1b8dd8e6d2d53972fcb3a6ceae22cac5 (patch) | |
tree | 281a2ac60f06bd405de0666708cdfadbf1ee8803 | |
parent | 67074b7aeaa276568bd8657641f57cb14c8906af (diff) | |
download | gnome-control-center-3a7533da1b8dd8e6d2d53972fcb3a6ceae22cac5.tar.gz |
printers: Use g_autoptr for the results of D-Bus calls
-rw-r--r-- | panels/printers/pp-job.c | 14 | ||||
-rw-r--r-- | panels/printers/pp-new-printer-dialog.c | 10 | ||||
-rw-r--r-- | panels/printers/pp-new-printer.c | 75 | ||||
-rw-r--r-- | panels/printers/pp-printer.c | 22 | ||||
-rw-r--r-- | panels/printers/pp-utils.c | 168 |
5 files changed, 110 insertions, 179 deletions
diff --git a/panels/printers/pp-job.c b/panels/printers/pp-job.c index 7664222a3..81e4341ec 100644 --- a/panels/printers/pp-job.c +++ b/panels/printers/pp-job.c @@ -72,17 +72,12 @@ pp_job_cancel_purge_async_dbus_cb (GObject *source_object, GAsyncResult *res, gpointer user_data) { - GVariant *output; + g_autoptr(GVariant) output = NULL; output = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source_object), res, NULL); g_object_unref (source_object); - - if (output != NULL) - { - g_variant_unref (output); - } } void @@ -123,17 +118,12 @@ pp_job_set_hold_until_async_dbus_cb (GObject *source_object, GAsyncResult *res, gpointer user_data) { - GVariant *output; + g_autoptr(GVariant) output = NULL; output = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source_object), res, NULL); g_object_unref (source_object); - - if (output) - { - g_variant_unref (output); - } } void diff --git a/panels/printers/pp-new-printer-dialog.c b/panels/printers/pp-new-printer-dialog.c index f4a6f9757..ebeba0849 100644 --- a/panels/printers/pp-new-printer-dialog.c +++ b/panels/printers/pp-new-printer-dialog.c @@ -895,10 +895,10 @@ group_physical_devices_dbus_cb (GObject *source_object, GAsyncResult *res, gpointer user_data) { - GVariant *output; - g_autoptr(GError) error = NULL; - gchar ***result = NULL; - gint i; + g_autoptr(GVariant) output = NULL; + g_autoptr(GError) error = NULL; + gchar ***result = NULL; + gint i; output = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source_object), res, @@ -927,8 +927,6 @@ group_physical_devices_dbus_cb (GObject *source_object, g_variant_unref (array); } - - g_variant_unref (output); } else if (error && error->domain == G_DBUS_ERROR && diff --git a/panels/printers/pp-new-printer.c b/panels/printers/pp-new-printer.c index b0412e183..4461dcfb3 100644 --- a/panels/printers/pp-new-printer.c +++ b/panels/printers/pp-new-printer.c @@ -392,7 +392,7 @@ printer_add_real_async_dbus_cb (GObject *source_object, gpointer user_data) { PpNewPrinter *self = user_data; - GVariant *output; + g_autoptr(GVariant) output = NULL; g_autoptr(GError) error = NULL; output = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source_object), @@ -409,8 +409,6 @@ printer_add_real_async_dbus_cb (GObject *source_object, { g_warning ("cups-pk-helper: addition of printer %s failed: %s", self->name, ret_error); } - - g_variant_unref (output); } else { @@ -524,7 +522,7 @@ printer_add_async_scb3 (GObject *source_object, gpointer user_data) { PpNewPrinter *self = user_data; - GVariant *output; + g_autoptr(GVariant) output = NULL; PPDName *ppd_item = NULL; g_autoptr(GError) error = NULL; @@ -536,7 +534,6 @@ printer_add_async_scb3 (GObject *source_object, if (output) { ppd_item = get_ppd_item_from_output (output); - g_variant_unref (output); } else { @@ -568,7 +565,7 @@ install_printer_drivers_cb (GObject *source_object, gpointer user_data) { PpNewPrinter *self = user_data; - GVariant *output; + g_autoptr(GVariant) output = NULL; g_autoptr(GError) error = NULL; output = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source_object), @@ -576,11 +573,7 @@ install_printer_drivers_cb (GObject *source_object, &error); g_object_unref (source_object); - if (output) - { - g_variant_unref (output); - } - else + if (output == NULL) { if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) g_warning ("%s", error->message); @@ -627,7 +620,7 @@ printer_add_async_scb (GObject *source_object, PpNewPrinter *self = user_data; GDBusConnection *bus; GVariantBuilder array_builder; - GVariant *output; + g_autoptr(GVariant) output = NULL; gboolean cancelled = FALSE; PPDName *ppd_item = NULL; g_autoptr(GError) error = NULL; @@ -640,7 +633,6 @@ printer_add_async_scb (GObject *source_object, if (output) { ppd_item = get_ppd_item_from_output (output); - g_variant_unref (output); } else { @@ -786,20 +778,16 @@ printer_set_accepting_jobs_cb (GObject *source_object, GAsyncResult *res, gpointer user_data) { - GVariant *output; - PCData *data = (PCData *) user_data; - g_autoptr(GError) error = NULL; + g_autoptr(GVariant) output = NULL; + PCData *data = (PCData *) user_data; + g_autoptr(GError) error = NULL; output = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source_object), res, &error); g_object_unref (source_object); - if (output) - { - g_variant_unref (output); - } - else + if (output == NULL) { if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) g_warning ("%s", error->message); @@ -814,20 +802,16 @@ printer_set_enabled_cb (GObject *source_object, GAsyncResult *res, gpointer user_data) { - GVariant *output; - PCData *data = (PCData *) user_data; - g_autoptr(GError) error = NULL; + g_autoptr(GVariant) output = NULL; + PCData *data = (PCData *) user_data; + g_autoptr(GError) error = NULL; output = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source_object), res, &error); g_object_unref (source_object); - if (output) - { - g_variant_unref (output); - } - else + if (output == NULL) { if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) g_warning ("%s", error->message); @@ -884,20 +868,16 @@ install_package_names_cb (GObject *source_object, GAsyncResult *res, gpointer user_data) { - GVariant *output; - IMEData *data = (IMEData *) user_data; - g_autoptr(GError) error = NULL; + g_autoptr(GVariant) output = NULL; + IMEData *data = (IMEData *) user_data; + g_autoptr(GError) error = NULL; output = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source_object), res, &error); g_object_unref (source_object); - if (output) - { - g_variant_unref (output); - } - else + if (output == NULL) { if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) g_warning ("%s", error->message); @@ -912,10 +892,10 @@ search_files_cb (GObject *source_object, GAsyncResult *res, gpointer user_data) { - GVariant *output; - IMEData *data = (IMEData *) user_data; - g_autoptr(GError) error = NULL; - GList *item; + g_autoptr(GVariant) output = NULL; + IMEData *data = (IMEData *) user_data; + g_autoptr(GError) error = NULL; + GList *item; output = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source_object), res, @@ -932,7 +912,6 @@ search_files_cb (GObject *source_object, if (!installed) data->packages = g_list_append (data->packages, g_strdup (package)); - g_variant_unref (output); } else { @@ -1010,11 +989,11 @@ get_missing_executables_cb (GObject *source_object, GAsyncResult *res, gpointer user_data) { - GVariant *output; - IMEData *data = (IMEData *) user_data; - g_autoptr(GError) error = NULL; - GList *executables = NULL; - GList *item; + g_autoptr(GVariant) output = NULL; + IMEData *data = (IMEData *) user_data; + g_autoptr(GError) error = NULL; + GList *executables = NULL; + GList *item; if (data->ppd_file_name) { @@ -1043,8 +1022,6 @@ get_missing_executables_cb (GObject *source_object, g_variant_unref (array); } - - g_variant_unref (output); } else if (error->domain == G_DBUS_ERROR && (error->code == G_DBUS_ERROR_SERVICE_UNKNOWN || diff --git a/panels/printers/pp-printer.c b/panels/printers/pp-printer.c index 817da6058..5a823ba44 100644 --- a/panels/printers/pp-printer.c +++ b/panels/printers/pp-printer.c @@ -155,11 +155,11 @@ printer_rename_dbus_cb (GObject *source_object, GAsyncResult *res, gpointer user_data) { - PpPrinter *self; - GVariant *output; - gboolean result = FALSE; - g_autoptr(GError) error = NULL; - GTask *task = user_data; + PpPrinter *self; + g_autoptr(GVariant) output = NULL; + gboolean result = FALSE; + g_autoptr(GError) error = NULL; + GTask *task = user_data; output = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source_object), res, @@ -186,8 +186,6 @@ printer_rename_dbus_cb (GObject *source_object, } g_task_return_boolean (task, result); - - g_variant_unref (output); } else { @@ -424,10 +422,10 @@ pp_printer_delete_dbus_cb (GObject *source_object, GAsyncResult *res, gpointer user_data) { - GVariant *output; - gboolean result = FALSE; - g_autoptr(GError) error = NULL; - GTask *task = user_data; + g_autoptr(GVariant) output = NULL; + gboolean result = FALSE; + g_autoptr(GError) error = NULL; + GTask *task = user_data; output = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source_object), res, @@ -448,8 +446,6 @@ pp_printer_delete_dbus_cb (GObject *source_object, result = TRUE; g_task_return_boolean (task, result); - - g_variant_unref (output); } else { diff --git a/panels/printers/pp-utils.c b/panels/printers/pp-utils.c index 486c655dc..1f5f1c7de 100644 --- a/panels/printers/pp-utils.c +++ b/panels/printers/pp-utils.c @@ -458,7 +458,7 @@ printer_rename (const gchar *old_name, } else { - GVariant *output; + g_autoptr(GVariant) output = NULL; g_autoptr(GError) add_error = NULL; output = g_dbus_connection_call_sync (bus, @@ -486,8 +486,6 @@ printer_rename (const gchar *old_name, g_variant_get (output, "(&s)", &ret_error); if (ret_error[0] != '\0') g_warning ("cups-pk-helper: rename of printer %s to %s failed: %s", old_name, new_name, ret_error); - - g_variant_unref (output); } else { @@ -538,10 +536,10 @@ gboolean printer_set_location (const gchar *printer_name, const gchar *location) { - GDBusConnection *bus; - GVariant *output; - gboolean result = FALSE; - g_autoptr(GError) error = NULL; + GDBusConnection *bus; + g_autoptr(GVariant) output = NULL; + gboolean result = FALSE; + g_autoptr(GError) error = NULL; if (!printer_name || !location) return TRUE; @@ -575,8 +573,6 @@ printer_set_location (const gchar *printer_name, g_warning ("cups-pk-helper: setting of location for printer %s failed: %s", printer_name, ret_error); else result = TRUE; - - g_variant_unref (output); } else { @@ -591,10 +587,10 @@ printer_set_accepting_jobs (const gchar *printer_name, gboolean accepting_jobs, const gchar *reason) { - GDBusConnection *bus; - GVariant *output; - gboolean result = FALSE; - g_autoptr(GError) error = NULL; + GDBusConnection *bus; + g_autoptr(GVariant) output = NULL; + gboolean result = FALSE; + g_autoptr(GError) error = NULL; if (!printer_name) return TRUE; @@ -631,7 +627,6 @@ printer_set_accepting_jobs (const gchar *printer_name, g_warning ("cups-pk-helper: setting of acceptance of jobs for printer %s failed: %s", printer_name, ret_error); else result = TRUE; - g_variant_unref (output); } else { @@ -645,10 +640,10 @@ gboolean printer_set_enabled (const gchar *printer_name, gboolean enabled) { - GDBusConnection *bus; - GVariant *output; - gboolean result = FALSE; - g_autoptr(GError) error = NULL; + GDBusConnection *bus; + g_autoptr(GVariant) output = NULL; + gboolean result = FALSE; + g_autoptr(GError) error = NULL; if (!printer_name) return TRUE; @@ -682,8 +677,6 @@ printer_set_enabled (const gchar *printer_name, g_warning ("cups-pk-helper: setting of enablement of printer %s failed: %s", printer_name, ret_error); else result = TRUE; - - g_variant_unref (output); } else { @@ -696,10 +689,10 @@ printer_set_enabled (const gchar *printer_name, gboolean printer_delete (const gchar *printer_name) { - GDBusConnection *bus; - GVariant *output; - gboolean result = FALSE; - g_autoptr(GError) error = NULL; + GDBusConnection *bus; + g_autoptr(GVariant) output = NULL; + gboolean result = FALSE; + g_autoptr(GError) error = NULL; if (!printer_name) return TRUE; @@ -733,8 +726,6 @@ printer_delete (const gchar *printer_name) g_warning ("cups-pk-helper: removing of printer %s failed: %s", printer_name, ret_error); else result = TRUE; - - g_variant_unref (output); } else { @@ -749,7 +740,6 @@ printer_set_default (const gchar *printer_name) { GDBusConnection *bus; const char *cups_server; - GVariant *output; gboolean result = FALSE; g_autoptr(GError) error = NULL; @@ -774,6 +764,8 @@ printer_set_default (const gchar *printer_name) } else { + g_autoptr(GVariant) output = NULL; + output = g_dbus_connection_call_sync (bus, MECHANISM_BUS, "/", @@ -796,8 +788,6 @@ printer_set_default (const gchar *printer_name) g_warning ("cups-pk-helper: setting default printer to %s failed: %s", printer_name, ret_error); else result = TRUE; - - g_variant_unref (output); } else { @@ -820,10 +810,10 @@ gboolean printer_set_shared (const gchar *printer_name, gboolean shared) { - GDBusConnection *bus; - GVariant *output; - gboolean result = FALSE; - g_autoptr(GError) error = NULL; + GDBusConnection *bus; + g_autoptr(GVariant) output = NULL; + gboolean result = FALSE; + g_autoptr(GError) error = NULL; if (!printer_name) return TRUE; @@ -857,8 +847,6 @@ printer_set_shared (const gchar *printer_name, g_warning ("cups-pk-helper: setting of sharing of printer %s failed: %s", printer_name, ret_error); else result = TRUE; - - g_variant_unref (output); } else { @@ -873,10 +861,10 @@ printer_set_job_sheets (const gchar *printer_name, const gchar *start_sheet, const gchar *end_sheet) { - GDBusConnection *bus; - GVariant *output; - g_autoptr(GError) error = NULL; - gboolean result = FALSE; + GDBusConnection *bus; + g_autoptr(GVariant) output = NULL; + g_autoptr(GError) error = NULL; + gboolean result = FALSE; if (!printer_name || !start_sheet || !end_sheet) return TRUE; @@ -910,8 +898,6 @@ printer_set_job_sheets (const gchar *printer_name, g_warning ("cups-pk-helper: setting of job sheets for printer %s failed: %s", printer_name, ret_error); else result = TRUE; - - g_variant_unref (output); } else { @@ -926,10 +912,10 @@ printer_set_policy (const gchar *printer_name, const gchar *policy, gboolean error_policy) { - GDBusConnection *bus; - GVariant *output; - gboolean result = FALSE; - g_autoptr(GError) error = NULL; + GDBusConnection *bus; + g_autoptr(GVariant) output = NULL; + gboolean result = FALSE; + g_autoptr(GError) error = NULL; if (!printer_name || !policy) return TRUE; @@ -976,8 +962,6 @@ printer_set_policy (const gchar *printer_name, g_warning ("cups-pk-helper: setting of a policy for printer %s failed: %s", printer_name, ret_error); else result = TRUE; - - g_variant_unref (output); } else { @@ -992,12 +976,12 @@ printer_set_users (const gchar *printer_name, gchar **users, gboolean allowed) { - GDBusConnection *bus; - GVariantBuilder array_builder; - gint i; - GVariant *output; - gboolean result = FALSE; - g_autoptr(GError) error = NULL; + GDBusConnection *bus; + GVariantBuilder array_builder; + gint i; + g_autoptr(GVariant) output = NULL; + gboolean result = FALSE; + g_autoptr(GError) error = NULL; if (!printer_name || !users) return TRUE; @@ -1048,8 +1032,6 @@ printer_set_users (const gchar *printer_name, g_warning ("cups-pk-helper: setting of access list for printer %s failed: %s", printer_name, ret_error); else result = TRUE; - - g_variant_unref (output); } else { @@ -1063,10 +1045,10 @@ gboolean class_add_printer (const gchar *class_name, const gchar *printer_name) { - GDBusConnection *bus; - GVariant *output; - gboolean result = FALSE; - g_autoptr(GError) error = NULL; + GDBusConnection *bus; + g_autoptr(GVariant) output = NULL; + gboolean result = FALSE; + g_autoptr(GError) error = NULL; if (!class_name || !printer_name) return TRUE; @@ -1100,8 +1082,6 @@ class_add_printer (const gchar *class_name, g_warning ("cups-pk-helper: adding of printer %s to class %s failed: %s", printer_name, class_name, ret_error); else result = TRUE; - - g_variant_unref (output); } else { @@ -1470,10 +1450,10 @@ printer_set_ppd_async_dbus_cb (GObject *source_object, GAsyncResult *res, gpointer user_data) { - GVariant *output; - gboolean result = FALSE; - PSPData *data = (PSPData *) user_data; - g_autoptr(GError) error = NULL; + g_autoptr(GVariant) output = NULL; + gboolean result = FALSE; + PSPData *data = (PSPData *) user_data; + g_autoptr(GError) error = NULL; output = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source_object), res, @@ -1489,8 +1469,6 @@ printer_set_ppd_async_dbus_cb (GObject *source_object, g_warning ("cups-pk-helper: setting of driver for printer %s failed: %s", data->printer_name, ret_error); else result = TRUE; - - g_variant_unref (output); } else { @@ -1905,14 +1883,14 @@ get_ppd_names_async_dbus_scb (GObject *source_object, GAsyncResult *res, gpointer user_data) { - GVariant *output; - PPDName *ppd_item; - PPDName **result = NULL; - GPNData *data = (GPNData *) user_data; - g_autoptr(GError) error = NULL; - GList *driver_list = NULL; - GList *iter; - gint i, j, n = 0; + g_autoptr(GVariant) output = NULL; + PPDName *ppd_item; + PPDName **result = NULL; + GPNData *data = (GPNData *) user_data; + g_autoptr(GError) error = NULL; + GList *driver_list = NULL; + GList *iter; + gint i, j, n = 0; static const char * const match_levels[] = { "exact-cmd", "exact", @@ -1970,8 +1948,6 @@ get_ppd_names_async_dbus_scb (GObject *source_object, g_variant_unref (array); } - - g_variant_unref (output); } else { @@ -2134,12 +2110,12 @@ get_device_attributes_async_dbus_cb (GObject *source_object, gpointer user_data) { - GVariant *output; - GDAData *data = (GDAData *) user_data; - g_autoptr(GError) error = NULL; - GList *tmp; - gchar *device_id = NULL; - gchar *device_make_and_model = NULL; + g_autoptr(GVariant) output = NULL; + GDAData *data = (GDAData *) user_data; + g_autoptr(GError) error = NULL; + GList *tmp; + gchar *device_id = NULL; + gchar *device_make_and_model = NULL; output = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source_object), res, @@ -2216,8 +2192,6 @@ get_device_attributes_async_dbus_cb (GObject *source_object, g_variant_unref (devices_variant); } - - g_variant_unref (output); } else { @@ -3154,10 +3128,10 @@ printer_add_option_async_dbus_cb (GObject *source_object, GAsyncResult *res, gpointer user_data) { - GVariant *output; - gboolean success = FALSE; - PAOData *data = (PAOData *) user_data; - g_autoptr(GError) error = NULL; + g_autoptr(GVariant) output = NULL; + gboolean success = FALSE; + PAOData *data = (PAOData *) user_data; + g_autoptr(GError) error = NULL; output = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source_object), res, @@ -3173,8 +3147,6 @@ printer_add_option_async_dbus_cb (GObject *source_object, g_warning ("cups-pk-helper: setting of an option failed: %s", ret_error); else success = TRUE; - - g_variant_unref (output); } else { @@ -3277,12 +3249,12 @@ get_cups_devices_async_dbus_cb (GObject *source_object, gpointer user_data) { - PpPrintDevice **devices = NULL; - GVariant *output; - GCDData *data = (GCDData *) user_data; - g_autoptr(GError) error = NULL; - GList *result = NULL; - gint num_of_devices = 0; + PpPrintDevice **devices = NULL; + g_autoptr(GVariant) output = NULL; + GCDData *data = (GCDData *) user_data; + g_autoptr(GError) error = NULL; + GList *result = NULL; + gint num_of_devices = 0; output = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source_object), res, @@ -3366,8 +3338,6 @@ get_cups_devices_async_dbus_cb (GObject *source_object, g_variant_unref (devices_variant); } - - g_variant_unref (output); } else { |