[gnome-control-center] printers: Use g_autoptr with strings
- From: Robert Ancell <rancell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center] printers: Use g_autoptr with strings
- Date: Mon, 4 Feb 2019 21:31:15 +0000 (UTC)
commit e9b9966e7d30a24481b271c77d3d2f13397a5ad2
Author: Robert Ancell <robert ancell canonical com>
Date: Tue Jun 26 11:52:41 2018 +1200
printers: Use g_autoptr with strings
panels/printers/cc-printers-panel.c | 25 ++---
panels/printers/pp-details-dialog.c | 25 ++---
panels/printers/pp-host.c | 24 ++---
panels/printers/pp-ipp-option-widget.c | 32 +++---
panels/printers/pp-job.c | 22 ++--
panels/printers/pp-jobs-dialog.c | 10 +-
panels/printers/pp-maintenance-command.c | 21 ++--
panels/printers/pp-new-printer-dialog.c | 60 ++++-------
panels/printers/pp-new-printer.c | 8 +-
panels/printers/pp-options-dialog.c | 12 +--
panels/printers/pp-ppd-option-widget.c | 21 ++--
panels/printers/pp-printer-entry.c | 72 +++++--------
panels/printers/pp-printer.c | 99 ++++++++---------
panels/printers/pp-samba.c | 19 ++--
panels/printers/pp-utils.c | 178 +++++++++++--------------------
15 files changed, 243 insertions(+), 385 deletions(-)
---
diff --git a/panels/printers/cc-printers-panel.c b/panels/printers/cc-printers-panel.c
index 5946cb5aa..2333e9257 100644
--- a/panels/printers/cc-printers-panel.c
+++ b/panels/printers/cc-printers-panel.c
@@ -700,8 +700,8 @@ on_printer_deleted (PpPrinterEntry *printer_entry,
{
CcPrintersPanel *self = (CcPrintersPanel*) user_data;
GtkLabel *label;
- gchar *notification_message;
- gchar *printer_name;
+ g_autofree gchar *notification_message = NULL;
+ g_autofree gchar *printer_name = NULL;
gtk_widget_hide (GTK_WIDGET (printer_entry));
@@ -718,10 +718,7 @@ on_printer_deleted (PpPrinterEntry *printer_entry,
gtk_builder_get_object (self->builder, "notification-label");
gtk_label_set_label (label, notification_message);
- g_free (notification_message);
-
self->deleted_printer_name = g_strdup (printer_name);
- g_free (printer_name);
gtk_revealer_set_reveal_child (self->notification, TRUE);
@@ -1155,11 +1152,11 @@ filter_function (GtkListBoxRow *row,
CcPrintersPanel *self = (CcPrintersPanel*) user_data;
GtkWidget *search_entry;
gboolean retval;
- gchar *search;
- gchar *name;
- gchar *location;
- gchar *printer_name;
- gchar *printer_location;
+ g_autofree gchar *search = NULL;
+ g_autofree gchar *name = NULL;
+ g_autofree gchar *location = NULL;
+ g_autofree gchar *printer_name = NULL;
+ g_autofree gchar *printer_location = NULL;
search_entry = (GtkWidget*)
gtk_builder_get_object (self->builder, "search-entry");
@@ -1175,20 +1172,12 @@ filter_function (GtkListBoxRow *row,
name = cc_util_normalize_casefold_and_unaccent (printer_name);
location = cc_util_normalize_casefold_and_unaccent (printer_location);
- g_free (printer_name);
- g_free (printer_location);
-
search = cc_util_normalize_casefold_and_unaccent (gtk_entry_get_text (GTK_ENTRY (search_entry)));
-
retval = strstr (name, search) != NULL;
if (location != NULL)
retval = retval || (strstr (location, search) != NULL);
- g_free (search);
- g_free (name);
- g_free (location);
-
return retval;
}
diff --git a/panels/printers/pp-details-dialog.c b/panels/printers/pp-details-dialog.c
index fe68f9ad7..36c7daee0 100644
--- a/panels/printers/pp-details-dialog.c
+++ b/panels/printers/pp-details-dialog.c
@@ -125,15 +125,13 @@ printer_name_changed (GtkEditable *editable,
{
PpDetailsDialog *self = (PpDetailsDialog *) user_data;
const gchar *name;
- gchar *title;
+ g_autofree gchar *title = NULL;
name = gtk_entry_get_text (GTK_ENTRY (self->printer_name_entry));
/* Translators: This is the title of the dialog. %s is the printer name. */
title = g_strdup_printf (_("%s Details"), name);
gtk_label_set_label (self->dialog_title, title);
-
- g_free (title);
}
static void
@@ -219,7 +217,7 @@ ppd_selection_dialog_response_cb (GtkDialog *dialog,
if (response_id == GTK_RESPONSE_OK)
{
- gchar *ppd_name;
+ g_autofree gchar *ppd_name = NULL;
ppd_name = pp_ppd_selection_dialog_get_ppd_name (self->pp_ppd_selection_dialog);
@@ -234,8 +232,6 @@ ppd_selection_dialog_response_cb (GtkDialog *dialog,
g_clear_pointer (&self->ppd_file_name, g_free);
self->ppd_file_name = g_strdup (ppd_name);
}
-
- g_free (ppd_name);
}
pp_ppd_selection_dialog_free (self->pp_ppd_selection_dialog);
@@ -259,8 +255,8 @@ static void
select_ppd_in_dialog (GtkButton *button,
PpDetailsDialog *self)
{
- gchar *device_id = NULL;
- gchar *manufacturer = NULL;
+ g_autofree gchar *device_id = NULL;
+ g_autofree gchar *manufacturer = NULL;
g_clear_pointer (&self->ppd_file_name, g_free);
self->ppd_file_name = g_strdup (cupsGetPPD (self->printer_name));
@@ -301,9 +297,6 @@ select_ppd_in_dialog (GtkButton *button,
manufacturer,
ppd_selection_dialog_response_cb,
self);
-
- g_free (manufacturer);
- g_free (device_id);
}
}
@@ -334,7 +327,7 @@ select_ppd_manually (GtkButton *button,
if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
{
- gchar *ppd_filename;
+ g_autofree gchar *ppd_filename = NULL;
ppd_filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
@@ -346,8 +339,6 @@ select_ppd_manually (GtkButton *button,
set_ppd_cb,
self);
}
-
- g_free (ppd_filename);
}
gtk_widget_destroy (dialog);
@@ -410,8 +401,8 @@ pp_details_dialog_new (GtkWindow *parent,
gboolean sensitive)
{
PpDetailsDialog *self;
- gchar *title;
- gchar *printer_url;
+ g_autofree gchar *title = NULL;
+ g_autofree gchar *printer_url = NULL;
self = g_object_new (PP_DETAILS_DIALOG_TYPE,
"transient-for", parent,
@@ -425,11 +416,9 @@ pp_details_dialog_new (GtkWindow *parent,
/* Translators: This is the title of the dialog. %s is the printer name. */
title = g_strdup_printf (_("%s Details"), printer_name);
gtk_label_set_label (self->dialog_title, title);
- g_free (title);
printer_url = g_strdup_printf ("<a href=\"http://%s:%d\">%s</a>", printer_address, ippPort (),
printer_address);
gtk_label_set_markup (GTK_LABEL (self->printer_address_label), printer_url);
- g_free (printer_url);
gtk_entry_set_text (GTK_ENTRY (self->printer_name_entry), printer_name);
gtk_entry_set_text (GTK_ENTRY (self->printer_location_entry), printer_location);
diff --git a/panels/printers/pp-host.c b/panels/printers/pp-host.c
index 15e65a574..f53ba217e 100644
--- a/panels/printers/pp-host.c
+++ b/panels/printers/pp-host.c
@@ -157,15 +157,15 @@ pp_host_new (const gchar *hostname)
static gchar **
line_split (gchar *line)
{
- gboolean escaped = FALSE;
- gboolean quoted = FALSE;
- gboolean in_word = FALSE;
- gchar **words = NULL;
- gchar **result = NULL;
- gchar *buffer = NULL;
- gchar ch;
- gint n = 0;
- gint i, j = 0, k = 0;
+ gboolean escaped = FALSE;
+ gboolean quoted = FALSE;
+ gboolean in_word = FALSE;
+ gchar **words = NULL;
+ gchar **result = NULL;
+ g_autofree gchar *buffer = NULL;
+ gchar ch;
+ gint n = 0;
+ gint i, j = 0, k = 0;
if (line)
{
@@ -233,7 +233,6 @@ line_split (gchar *line)
result = g_strdupv (words);
g_strfreev (words);
- g_free (buffer);
return result;
}
@@ -275,7 +274,6 @@ _pp_host_get_snmp_devices_thread (GTask *task,
if (exit_status == 0 && stdout_string)
{
g_auto(GStrv) printer_informations = NULL;
- g_autofree gchar *device_name = NULL;
gint length;
printer_informations = line_split (stdout_string);
@@ -283,8 +281,10 @@ _pp_host_get_snmp_devices_thread (GTask *task,
if (length >= 4)
{
+ g_autofree gchar *device_name = NULL;
+
device_name = g_strdup (printer_informations[3]);
- device_name = g_strcanon (device_name, ALLOWED_CHARACTERS, '-');
+ g_strcanon (device_name, ALLOWED_CHARACTERS, '-');
is_network_device = g_strcmp0 (printer_informations[0], "network") == 0;
device = g_object_new (PP_TYPE_PRINT_DEVICE,
diff --git a/panels/printers/pp-ipp-option-widget.c b/panels/printers/pp-ipp-option-widget.c
index 4435cdd00..430325ac3 100644
--- a/panels/printers/pp-ipp-option-widget.c
+++ b/panels/printers/pp-ipp-option-widget.c
@@ -230,18 +230,17 @@ set_cb (GtkTreeModel *model,
GtkTreeIter *iter,
gpointer data)
{
- struct ComboSet *set_data = data;
- gboolean found;
- char *value;
+ struct ComboSet *set_data = data;
+ g_autofree gchar *value = NULL;
gtk_tree_model_get (model, iter, VALUE_COLUMN, &value, -1);
- found = (strcmp (value, set_data->value) == 0);
- g_free (value);
-
- if (found)
- gtk_combo_box_set_active_iter (set_data->combo, iter);
+ if (strcmp (value, set_data->value) == 0)
+ {
+ gtk_combo_box_set_active_iter (set_data->combo, iter);
+ return TRUE;
+ }
- return found;
+ return FALSE;
}
static void
@@ -374,7 +373,6 @@ construct_widget (PpIPPOptionWidget *self)
{
gboolean trivial_option = FALSE;
gboolean result = FALSE;
- gchar *value;
gint i;
if (self->option_supported)
@@ -414,12 +412,13 @@ construct_widget (PpIPPOptionWidget *self)
for (i = 0; i < self->option_supported->num_of_values; i++)
{
+ g_autofree gchar *value = NULL;
+
value = g_strdup_printf ("%d",
self->option_supported->attribute_values[i].integer_value);
combo_box_append (self->combo,
ipp_choice_translate (self->option_name,
value),
value);
- g_free (value);
}
gtk_box_pack_start (GTK_BOX (self), self->combo, FALSE, FALSE, 0);
@@ -464,8 +463,6 @@ static void
update_widget_real (PpIPPOptionWidget *self)
{
IPPAttribute *attr = NULL;
- gchar *value;
- gchar *attr_name;
if (self->option_default)
{
@@ -476,10 +473,9 @@ update_widget_real (PpIPPOptionWidget *self)
}
else if (self->ipp_attribute)
{
- attr_name = g_strdup_printf ("%s-default", self->option_name);
+ g_autofree gchar *attr_name = g_strdup_printf ("%s-default", self->option_name);
attr = ipp_attribute_copy (g_hash_table_lookup (self->ipp_attribute, attr_name));
- g_free (attr_name);
g_hash_table_unref (self->ipp_attribute);
self->ipp_attribute = NULL;
}
@@ -505,15 +501,13 @@ update_widget_real (PpIPPOptionWidget *self)
if (attr && attr->num_of_values > 0 &&
attr->attribute_type == IPP_ATTRIBUTE_TYPE_INTEGER)
{
- value = g_strdup_printf ("%d", attr->attribute_values[0].integer_value);
+ g_autofree gchar *value = g_strdup_printf ("%d", attr->attribute_values[0].integer_value);
combo_box_set (self->combo, value);
- g_free (value);
}
else
{
- value = g_strdup_printf ("%d", self->option_supported->attribute_values[0].integer_value);
+ g_autofree gchar *value = g_strdup_printf ("%d",
self->option_supported->attribute_values[0].integer_value);
combo_box_set (self->combo, value);
- g_free (value);
}
g_signal_handlers_unblock_by_func (self->combo, combo_changed_cb, self);
diff --git a/panels/printers/pp-job.c b/panels/printers/pp-job.c
index 77ea6a249..7664222a3 100644
--- a/panels/printers/pp-job.c
+++ b/panels/printers/pp-job.c
@@ -285,14 +285,14 @@ _pp_job_get_attributes_thread (GTask *task,
GCancellable *cancellable)
{
PpJob *self = PP_JOB (source_object);
- ipp_attribute_t *attr = NULL;
- GVariantBuilder builder;
- GVariant *attributes = NULL;
- gchar **attributes_names = task_data;
- ipp_t *request;
- ipp_t *response = NULL;
- gchar *job_uri;
- gint i, j, length = 0, n_attrs = 0;
+ ipp_attribute_t *attr = NULL;
+ GVariantBuilder builder;
+ GVariant *attributes = NULL;
+ gchar **attributes_names = task_data;
+ ipp_t *request;
+ ipp_t *response = NULL;
+ g_autofree gchar *job_uri = NULL;
+ gint i, j, length = 0, n_attrs = 0;
job_uri = g_strdup_printf ("ipp://localhost/jobs/%d", self->id);
@@ -386,7 +386,6 @@ _pp_job_get_attributes_thread (GTask *task,
attributes = g_variant_builder_end (&builder);
}
- g_free (job_uri);
g_task_return_pointer (task, attributes, (GDestroyNotify) g_variant_unref);
}
@@ -428,12 +427,11 @@ _pp_job_authenticate_thread (GTask *task,
gchar **auth_info = task_data;
ipp_t *request;
ipp_t *response = NULL;
- gchar *job_uri;
gint length;
if (auth_info != NULL)
{
- job_uri = g_strdup_printf ("ipp://localhost/jobs/%d", self->id);
+ g_autofree gchar *job_uri = g_strdup_printf ("ipp://localhost/jobs/%d", self->id);
length = g_strv_length (auth_info);
@@ -450,8 +448,6 @@ _pp_job_authenticate_thread (GTask *task,
if (response != NULL)
ippDelete (response);
-
- g_free (job_uri);
}
g_task_return_boolean (task, result);
diff --git a/panels/printers/pp-jobs-dialog.c b/panels/printers/pp-jobs-dialog.c
index 875862ede..4aa0452e5 100644
--- a/panels/printers/pp-jobs-dialog.c
+++ b/panels/printers/pp-jobs-dialog.c
@@ -327,7 +327,6 @@ update_jobs_list_cb (GObject *source_object,
GList *jobs, *l;
PpJob *job;
gchar **auth_info_required = NULL;
- gchar *text;
gint num_of_jobs, num_of_auth_jobs = 0;
g_list_store_remove_all (self->store);
@@ -383,12 +382,13 @@ update_jobs_list_cb (GObject *source_object,
infobar = GTK_WIDGET (gtk_builder_get_object (GTK_BUILDER (self->builder), "authentication-infobar"));
if (num_of_auth_jobs > 0)
{
+ g_autofree gchar *text = NULL;
+
label = GTK_WIDGET (gtk_builder_get_object (GTK_BUILDER (self->builder), "authenticate-jobs-label"));
/* Translators: This label shows how many jobs of this printer needs to be authenticated to be
printed. */
text = g_strdup_printf (ngettext ("%u Job Requires Authentication", "%u Jobs Require Authentication",
num_of_auth_jobs), num_of_auth_jobs);
gtk_label_set_text (GTK_LABEL (label), text);
- g_free (text);
gtk_widget_show (infobar);
}
@@ -559,9 +559,9 @@ pp_jobs_dialog_new (GtkWindow *parent,
GtkWidget *widget;
g_autoptr(GError) error = NULL;
gchar *objects[] = { "jobs-dialog", "authentication_popover", NULL };
- gchar *text;
+ g_autofree gchar *text = NULL;
guint builder_result;
- gchar *title;
+ g_autofree gchar *title = NULL;
self = g_new0 (PpJobsDialog, 1);
@@ -612,13 +612,11 @@ pp_jobs_dialog_new (GtkWindow *parent,
/* Translators: This is the printer name for which we are showing the active jobs */
title = g_strdup_printf (C_("Printer jobs dialog title", "%s — Active Jobs"), printer_name);
gtk_window_set_title (GTK_WINDOW (self->dialog), title);
- g_free (title);
/* Translators: The printer needs authentication info to print. */
text = g_strdup_printf (_("Enter credentials to print from %s."), printer_name);
widget = GTK_WIDGET (gtk_builder_get_object (GTK_BUILDER (self->builder), "authentication-label"));
gtk_label_set_text (GTK_LABEL (widget), text);
- g_free (text);
self->listbox = GTK_LIST_BOX (gtk_builder_get_object (self->builder, "jobs-listbox"));
gtk_list_box_set_header_func (self->listbox,
diff --git a/panels/printers/pp-maintenance-command.c b/panels/printers/pp-maintenance-command.c
index ae59b7ce6..feb144ce7 100644
--- a/panels/printers/pp-maintenance-command.c
+++ b/panels/printers/pp-maintenance-command.c
@@ -204,11 +204,11 @@ _pp_maintenance_command_execute_thread (GTask *task,
if (_pp_maintenance_command_is_supported (self->printer_name, self->command))
{
- ipp_t *request;
- ipp_t *response = NULL;
- gchar *printer_uri;
- gchar *file_name = NULL;
- int fd = -1;
+ ipp_t *request;
+ ipp_t *response = NULL;
+ g_autofree gchar *printer_uri = NULL;
+ g_autofree gchar *file_name = NULL;
+ int fd = -1;
printer_uri = g_strdup_printf ("ipp://localhost/printers/%s",
self->printer_name);
@@ -249,9 +249,6 @@ _pp_maintenance_command_execute_thread (GTask *task,
ippDelete (response);
}
}
-
- g_free (file_name);
- g_free (printer_uri);
}
else
{
@@ -302,8 +299,7 @@ _pp_maintenance_command_is_supported (const gchar *printer_name,
gboolean is_supported = FALSE;
ipp_t *request;
ipp_t *response = NULL;
- gchar *printer_uri;
- gchar *command_lowercase;
+ g_autofree gchar *printer_uri = NULL;
GPtrArray *available_commands = NULL;
int i;
@@ -342,7 +338,7 @@ _pp_maintenance_command_is_supported (const gchar *printer_name,
if (available_commands != NULL)
{
- command_lowercase = g_ascii_strdown (command, -1);
+ g_autofree gchar *command_lowercase = g_ascii_strdown (command, -1);
for (i = 0; i < available_commands->len; ++i)
{
const gchar *available_command = g_ptr_array_index (available_commands, i);
@@ -353,12 +349,9 @@ _pp_maintenance_command_is_supported (const gchar *printer_name,
}
}
- g_free (command_lowercase);
g_ptr_array_free (available_commands, TRUE);
}
- g_free (printer_uri);
-
return is_supported;
}
diff --git a/panels/printers/pp-new-printer-dialog.c b/panels/printers/pp-new-printer-dialog.c
index bf2769333..93e95e9a8 100644
--- a/panels/printers/pp-new-printer-dialog.c
+++ b/panels/printers/pp-new-printer-dialog.c
@@ -372,22 +372,21 @@ on_authentication_required (PpHost *host,
gpointer user_data)
{
PpNewPrinterDialog *self = user_data;
- gchar *text, *hostname;
+ g_autofree gchar *hostname = NULL;
+ g_autofree gchar *title = NULL;
+ g_autofree gchar *text = NULL;
gtk_header_bar_set_subtitle (GTK_HEADER_BAR (WID ("headerbar")), NULL);
gtk_header_bar_set_title (GTK_HEADER_BAR (WID ("headerbar")), _("Unlock Print Server"));
g_object_get (G_OBJECT (host), "hostname", &hostname, NULL);
/* Translators: Samba server needs authentication of the user to show list of its printers. */
- text = g_strdup_printf (_("Unlock %s."), hostname);
- gtk_label_set_text (GTK_LABEL (WID ("authentication-title")), text);
- g_free (text);
+ title = g_strdup_printf (_("Unlock %s."), hostname);
+ gtk_label_set_text (GTK_LABEL (WID ("authentication-title")), title);
/* Translators: Samba server needs authentication of the user to show list of its printers. */
text = g_strdup_printf (_("Enter username and password to view printers on %s."), hostname);
gtk_label_set_text (GTK_LABEL (WID ("authentication-text")), text);
- g_free (hostname);
- g_free (text);
go_to_page (self, AUTHENTICATION_PAGE);
@@ -686,17 +685,14 @@ add_device_to_list (PpNewPrinterDialog *self,
{
PpPrintDevice *store_device;
GList *original_names_list = NULL;
- gchar *canonicalized_name = NULL;
- gchar *host_name;
gint acquisistion_method;
if (device)
{
if (pp_print_device_get_host_name (device) == NULL)
{
- host_name = guess_device_hostname (device);
+ g_autofree gchar *host_name = guess_device_hostname (device);
g_object_set (device, "host-name", host_name, NULL);
- g_free (host_name);
}
acquisistion_method = pp_print_device_get_acquisition_method (device);
@@ -710,6 +706,8 @@ add_device_to_list (PpNewPrinterDialog *self,
(acquisistion_method == ACQUISITION_METHOD_JETDIRECT ||
acquisistion_method == ACQUISITION_METHOD_LPD)))
{
+ g_autofree gchar *canonicalized_name = NULL;
+
g_object_set (device,
"device-original-name", pp_print_device_get_device_name (device),
NULL);
@@ -733,8 +731,6 @@ add_device_to_list (PpNewPrinterDialog *self,
"device-name", canonicalized_name,
NULL);
- g_free (canonicalized_name);
-
if (pp_print_device_get_acquisition_method (device) == ACQUISITION_METHOD_DEFAULT_CUPS_SERVER)
self->local_cups_devices = g_list_append (self->local_cups_devices, g_object_ref (device));
else
@@ -1383,9 +1379,9 @@ parse_uri (const gchar *uri,
gchar **host,
gint *port)
{
- const gchar *tmp = NULL;
- gchar *resulting_host = NULL;
- gchar *position;
+ const gchar *tmp = NULL;
+ g_autofree gchar *resulting_host = NULL;
+ gchar *position;
*port = PP_HOST_UNSET_PORT;
@@ -1424,8 +1420,6 @@ parse_uri (const gchar *uri,
G_URI_RESERVED_CHARS_GENERIC_DELIMITERS
G_URI_RESERVED_CHARS_SUBCOMPONENT_DELIMITERS);
- g_free (resulting_host);
-
return TRUE;
}
@@ -1523,9 +1517,7 @@ search_address (const gchar *text,
gboolean subfound;
gboolean next_set;
gboolean cont;
- gchar *lowercase_name;
- gchar *lowercase_location;
- gchar *lowercase_text;
+ g_autofree gchar *lowercase_text = NULL;
gchar **words;
gint words_length = 0;
gint i;
@@ -1533,7 +1525,6 @@ search_address (const gchar *text,
lowercase_text = g_ascii_strdown (text, -1);
words = g_strsplit_set (lowercase_text, " ", -1);
- g_free (lowercase_text);
if (words)
{
@@ -1542,6 +1533,9 @@ search_address (const gchar *text,
cont = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (self->store), &iter);
while (cont)
{
+ g_autofree gchar *lowercase_name = NULL;
+ g_autofree gchar *lowercase_location = NULL;
+
gtk_tree_model_get (GTK_TREE_MODEL (self->store), &iter,
DEVICE_COLUMN, &device,
-1);
@@ -1567,8 +1561,6 @@ search_address (const gchar *text,
DEVICE_VISIBLE_COLUMN, subfound,
-1);
- g_free (lowercase_location);
- g_free (lowercase_name);
g_object_unref (device);
cont = gtk_tree_model_iter_next (GTK_TREE_MODEL (self->store), &iter);
@@ -1715,7 +1707,6 @@ set_device (PpNewPrinterDialog *self,
GtkTreeIter *iter)
{
GtkTreeIter titer;
- gchar *description;
gint acquisition_method;
if (device != NULL)
@@ -1732,6 +1723,8 @@ set_device (PpNewPrinterDialog *self,
acquisition_method == ACQUISITION_METHOD_SAMBA_HOST ||
acquisition_method == ACQUISITION_METHOD_SAMBA))
{
+ g_autofree gchar *description = NULL;
+
description = get_local_scheme_description_from_uri (pp_print_device_get_device_uri (device));
if (description == NULL)
{
@@ -1758,8 +1751,6 @@ set_device (PpNewPrinterDialog *self,
DEVICE_VISIBLE_COLUMN, TRUE,
DEVICE_COLUMN, device,
-1);
-
- g_free (description);
}
else if (pp_print_device_is_authenticated_server (device) &&
pp_print_device_get_host_name (device) != NULL)
@@ -1886,9 +1877,8 @@ cell_data_func (GtkTreeViewColumn *tree_column,
{
PpNewPrinterDialog *self = user_data;
gboolean selected = FALSE;
- gchar *name = NULL;
- gchar *description = NULL;
- gchar *text;
+ g_autofree gchar *name = NULL;
+ g_autofree gchar *description = NULL;
selected = gtk_tree_selection_iter_is_selected (gtk_tree_view_get_selection (self->treeview), iter);
@@ -1899,6 +1889,8 @@ cell_data_func (GtkTreeViewColumn *tree_column,
if (name != NULL)
{
+ g_autofree gchar *text = NULL;
+
if (description != NULL)
{
if (selected)
@@ -1919,12 +1911,7 @@ cell_data_func (GtkTreeViewColumn *tree_column,
g_object_set (G_OBJECT (cell),
"markup", text,
NULL);
-
- g_free (text);
}
-
- g_free (name);
- g_free (description);
}
static void
@@ -2026,7 +2013,6 @@ ppd_selection_cb (GtkDialog *_dialog,
GList *original_names_list = NULL;
gchar *ppd_name;
gchar *ppd_display_name;
- gchar *printer_name;
guint window_id = 0;
gint acquisition_method;
@@ -2044,6 +2030,8 @@ ppd_selection_cb (GtkDialog *_dialog,
acquisition_method == ACQUISITION_METHOD_LPD) &&
ppd_display_name != NULL)
{
+ g_autofree gchar *printer_name = NULL;
+
g_object_set (self->new_device,
"device-name", ppd_display_name,
"device-original-name", ppd_display_name,
@@ -2067,8 +2055,6 @@ ppd_selection_cb (GtkDialog *_dialog,
"device-name", printer_name,
"device-original-name", printer_name,
NULL);
-
- g_free (printer_name);
}
emit_pre_response (self,
diff --git a/panels/printers/pp-new-printer.c b/panels/printers/pp-new-printer.c
index 3045a0ee4..bcd4c2d5c 100644
--- a/panels/printers/pp-new-printer.c
+++ b/panels/printers/pp-new-printer.c
@@ -485,15 +485,15 @@ get_ppd_item_from_output (GVariant *output)
{
GVariantIter *iter;
GVariant *item;
- gchar *driver;
- gchar *match;
for (j = 0; j < G_N_ELEMENTS (match_levels) && !ppd_item; j++)
{
g_variant_get (array, "a(ss)", &iter);
while ((item = g_variant_iter_next_value (iter)) && !ppd_item)
{
- g_variant_get (item, "(ss)", &driver, &match);
+ const gchar *driver, *match;
+
+ g_variant_get (item, "(&s&s)", &driver, &match);
if (g_str_equal (match, match_levels[j]))
{
ppd_item = g_new0 (PPDName, 1);
@@ -511,8 +511,6 @@ get_ppd_item_from_output (GVariant *output)
ppd_item->ppd_match_level = PPD_NO_MATCH;
}
- g_free (driver);
- g_free (match);
g_variant_unref (item);
}
}
diff --git a/panels/printers/pp-options-dialog.c b/panels/printers/pp-options-dialog.c
index d88980aca..7bc32920f 100644
--- a/panels/printers/pp-options-dialog.c
+++ b/panels/printers/pp-options-dialog.c
@@ -867,11 +867,11 @@ test_page_cb (GtkButton *button,
if (self->printer_name)
{
- const gchar *const dirs[] = { "/usr/share/cups",
- "/usr/local/share/cups",
- NULL };
- const gchar *datadir = NULL;
- gchar *filename = NULL;
+ const gchar *const dirs[] = { "/usr/share/cups",
+ "/usr/local/share/cups",
+ NULL };
+ const gchar *datadir = NULL;
+ g_autofree gchar *filename = NULL;
datadir = getenv ("CUPS_DATADIR");
if (datadir != NULL)
@@ -896,8 +896,6 @@ test_page_cb (GtkButton *button,
NULL,
print_test_page_cb,
NULL);
-
- g_free (filename);
}
else
{
diff --git a/panels/printers/pp-ppd-option-widget.c b/panels/printers/pp-ppd-option-widget.c
index ae8b89369..11c54fcec 100644
--- a/panels/printers/pp-ppd-option-widget.c
+++ b/panels/printers/pp-ppd-option-widget.c
@@ -288,18 +288,18 @@ set_cb (GtkTreeModel *model,
GtkTreeIter *iter,
gpointer data)
{
- struct ComboSet *set_data = data;
- gboolean found;
- char *value;
+ struct ComboSet *set_data = data;
+ g_autofree gchar *value = NULL;
gtk_tree_model_get (model, iter, VALUE_COLUMN, &value, -1);
- found = (strcmp (value, set_data->value) == 0);
- g_free (value);
- if (found)
- gtk_combo_box_set_active_iter (set_data->combo, iter);
+ if (strcmp (value, set_data->value) == 0)
+ {
+ gtk_combo_box_set_active_iter (set_data->combo, iter);
+ return TRUE;
+ }
- return found;
+ return FALSE;
}
static void
@@ -467,7 +467,6 @@ update_widget_real (PpPPDOptionWidget *self)
{
ppd_option_t *option = NULL, *iter;
ppd_file_t *ppd_file;
- gchar *value = NULL;
gint i;
if (self->option)
@@ -504,6 +503,8 @@ update_widget_real (PpPPDOptionWidget *self)
if (option)
{
+ g_autofree gchar *value = NULL;
+
for (i = 0; i < option->num_choices; i++)
if (option->choices[i].marked)
value = g_strdup (option->choices[i].choice);
@@ -539,8 +540,6 @@ update_widget_real (PpPPDOptionWidget *self)
default:
break;
}
-
- g_free (value);
}
if (option->conflicted)
diff --git a/panels/printers/pp-printer-entry.c b/panels/printers/pp-printer-entry.c
index 665550a80..0ac802996 100644
--- a/panels/printers/pp-printer-entry.c
+++ b/panels/printers/pp-printer-entry.c
@@ -202,13 +202,13 @@ markers_cmp (gconstpointer a,
}
static gchar *
-sanitize_printer_model (gchar *printer_make_and_model)
+sanitize_printer_model (const gchar *printer_make_and_model)
{
- gchar *breakpoint = NULL, *tmp = NULL, *tmp2 = NULL;
- gchar *printer_model = NULL;
- gchar backup;
- size_t length = 0;
- gchar *forbiden[] = {
+ gchar *breakpoint = NULL, *tmp2 = NULL;
+ g_autofree gchar *tmp = NULL;
+ gchar backup;
+ size_t length = 0;
+ gchar *forbiden[] = {
"foomatic",
",",
"hpijs",
@@ -236,14 +236,12 @@ sanitize_printer_model (gchar *printer_make_and_model)
*breakpoint = backup;
if (length > 0)
- printer_model = g_strndup (printer_make_and_model, length);
+ return g_strndup (printer_make_and_model, length);
}
else
- printer_model = g_strdup (printer_make_and_model);
+ return g_strdup (printer_make_and_model);
- g_free (tmp);
-
- return printer_model;
+ return NULL;
}
static gboolean
@@ -283,7 +281,7 @@ supply_levels_draw_cb (GtkWidget *widget,
{
GtkStyleContext *context;
gboolean is_empty = TRUE;
- gchar *tooltip_text = NULL;
+ g_autofree gchar *tooltip_text = NULL;
gint width;
gint height;
int i;
@@ -303,7 +301,6 @@ supply_levels_draw_cb (GtkWidget *widget,
gchar **marker_colorsv = NULL;
gchar **marker_namesv = NULL;
gchar **marker_typesv = NULL;
- gchar *tmp = NULL;
gtk_style_context_save (context);
@@ -366,12 +363,10 @@ supply_levels_draw_cb (GtkWidget *widget,
if (tooltip_text)
{
- tmp = g_strdup_printf ("%s\n%s",
- tooltip_text,
- ((MarkerItem*) tmp_list->data)->name);
- g_free (tooltip_text);
- tooltip_text = tmp;
- tmp = NULL;
+ g_autofree gchar *old_tooltip_text = g_steal_pointer (&tooltip_text);
+ tooltip_text = g_strdup_printf ("%s\n%s",
+ old_tooltip_text,
+ ((MarkerItem*) tmp_list->data)->name);
}
else
tooltip_text = g_strdup_printf ("%s",
@@ -394,7 +389,6 @@ supply_levels_draw_cb (GtkWidget *widget,
if (tooltip_text)
{
gtk_widget_set_tooltip_text (widget, tooltip_text);
- g_free (tooltip_text);
}
else
{
@@ -587,7 +581,7 @@ get_jobs_cb (GObject *source_object,
PpPrinter *printer = PP_PRINTER (source_object);
g_autoptr(GError) error = NULL;
GList *jobs;
- gchar *button_label;
+ g_autofree gchar *button_label = NULL;
gint num_jobs;
jobs = pp_printer_get_jobs_finish (printer, result, &error);
@@ -625,8 +619,6 @@ get_jobs_cb (GObject *source_object,
pp_jobs_dialog_update (self->pp_jobs_dialog);
}
- g_free (button_label);
-
g_clear_object (&self->get_jobs_cancellable);
}
@@ -735,21 +727,20 @@ PpPrinterEntry *
pp_printer_entry_new (cups_dest_t printer,
gboolean is_authorized)
{
- PpPrinterEntry *self;
- cups_ptype_t printer_type = 0;
- gboolean is_accepting_jobs = TRUE;
- gboolean ink_supply_is_empty;
- gchar *instance;
- gchar *printer_uri = NULL;
- gchar *location = NULL;
- gchar *printer_icon_name = NULL;
- gchar *default_icon_name = NULL;
- gchar *printer_make_and_model = NULL;
- gchar *reason = NULL;
- gchar **printer_reasons = NULL;
- gchar *status = NULL;
- gchar *printer_status = NULL;
- int i, j;
+ PpPrinterEntry *self;
+ cups_ptype_t printer_type = 0;
+ gboolean is_accepting_jobs = TRUE;
+ gboolean ink_supply_is_empty;
+ g_autofree gchar *instance = NULL;
+ const gchar *printer_uri = NULL;
+ const gchar *location = NULL;
+ g_autofree gchar *printer_icon_name = NULL;
+ const gchar *printer_make_and_model = NULL;
+ const gchar *reason = NULL;
+ gchar **printer_reasons = NULL;
+ g_autofree gchar *status = NULL;
+ g_autofree gchar *printer_status = NULL;
+ int i, j;
static const char * const reasons[] =
{
"toner-low",
@@ -949,7 +940,6 @@ pp_printer_entry_new (cups_dest_t printer,
gtk_image_set_from_icon_name (self->printer_icon, printer_icon_name, GTK_ICON_SIZE_DIALOG);
gtk_label_set_text (self->printer_status, printer_status);
- g_free (printer_status);
gtk_label_set_text (self->printer_name_label, instance);
g_signal_handlers_block_by_func (self->printer_default_checkbutton, set_as_default_printer, self);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->printer_default_checkbutton), printer.is_default);
@@ -987,10 +977,6 @@ pp_printer_entry_new (cups_dest_t printer,
gtk_widget_set_sensitive (GTK_WIDGET (self->printer_default_checkbutton), self->is_authorized);
gtk_widget_set_sensitive (GTK_WIDGET (self->remove_printer_menuitem), self->is_authorized);
- g_free (instance);
- g_free (printer_icon_name);
- g_free (default_icon_name);
-
return self;
}
diff --git a/panels/printers/pp-printer.c b/panels/printers/pp-printer.c
index b21e7fa46..8e3444ec8 100644
--- a/panels/printers/pp-printer.c
+++ b/panels/printers/pp-printer.c
@@ -133,10 +133,10 @@ printer_rename_thread (GTask *task,
gpointer task_data,
GCancellable *cancellable)
{
- PpPrinter *self = PP_PRINTER (source_object);
- gboolean result;
- gchar *new_printer_name = task_data;
- gchar *old_printer_name;
+ PpPrinter *self = PP_PRINTER (source_object);
+ gboolean result;
+ gchar *new_printer_name = task_data;
+ g_autofree gchar *old_printer_name = NULL;
g_object_get (self, "printer-name", &old_printer_name, NULL);
@@ -147,8 +147,6 @@ printer_rename_thread (GTask *task,
g_object_set (self, "printer-name", new_printer_name, NULL);
}
- g_free (old_printer_name);
-
g_task_return_boolean (task, result);
}
@@ -162,7 +160,6 @@ printer_rename_dbus_cb (GObject *source_object,
gboolean result = FALSE;
g_autoptr(GError) error = NULL;
GTask *task = user_data;
- gchar *old_printer_name;
output = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source_object),
res,
@@ -171,6 +168,7 @@ printer_rename_dbus_cb (GObject *source_object,
if (output != NULL)
{
+ g_autofree gchar *old_printer_name = NULL;
const gchar *ret_error;
self = g_task_get_source_object (task);
@@ -189,7 +187,6 @@ printer_rename_dbus_cb (GObject *source_object,
g_task_return_boolean (task, result);
- g_free (old_printer_name);
g_variant_unref (output);
}
else
@@ -217,11 +214,12 @@ get_bus_cb (GObject *source_object,
GDBusConnection *bus;
g_autoptr(GError) error = NULL;
GTask *task = user_data;
- gchar *printer_name;
bus = g_bus_get_finish (res, &error);
if (bus != NULL)
{
+ g_autofree gchar *printer_name = NULL;
+
g_object_get (g_task_get_source_object (task),
"printer-name", &printer_name,
NULL);
@@ -239,8 +237,6 @@ get_bus_cb (GObject *source_object,
g_task_get_cancellable (task),
printer_rename_dbus_cb,
task);
-
- g_free (printer_name);
}
else
{
@@ -292,24 +288,24 @@ get_jobs_thread (GTask *task,
gpointer task_data,
GCancellable *cancellable)
{
- ipp_attribute_t *attr = NULL;
- static gchar *printer_attributes[] = { "auth-info-required" };
- GetJobsData *get_jobs_data = task_data;
- cups_job_t *jobs = NULL;
- PpPrinter *self = PP_PRINTER (source_object);
- gboolean auth_info_is_required;
- PpJob *job;
- ipp_t *job_request;
- ipp_t *job_response;
- ipp_t *printer_request;
- ipp_t *printer_response;
- gchar *job_uri;
- gchar *printer_uri;
- gchar **auth_info_required = NULL;
- gchar *printer_name;
- GList *list = NULL;
- gint num_jobs;
- gint i, j;
+ ipp_attribute_t *attr = NULL;
+ static gchar *printer_attributes[] = { "auth-info-required" };
+ GetJobsData *get_jobs_data = task_data;
+ cups_job_t *jobs = NULL;
+ PpPrinter *self = PP_PRINTER (source_object);
+ gboolean auth_info_is_required;
+ PpJob *job;
+ ipp_t *job_request;
+ ipp_t *job_response;
+ ipp_t *printer_request;
+ ipp_t *printer_response;
+ gchar *job_uri;
+ gchar *printer_uri;
+ gchar **auth_info_required = NULL;
+ g_autofree gchar *printer_name = NULL;
+ GList *list = NULL;
+ gint num_jobs;
+ gint i, j;
g_object_get (self, "printer-name", &printer_name, NULL);
@@ -323,7 +319,7 @@ get_jobs_thread (GTask *task,
auth_info_is_required = FALSE;
if (jobs[i].state == IPP_JOB_HELD)
{
- job_uri = g_strdup_printf ("ipp://localhost/jobs/%d", jobs[i].id);
+ g_autofree gchar *job_uri = g_strdup_printf ("ipp://localhost/jobs/%d", jobs[i].id);
job_request = ippNewRequest (IPP_GET_JOB_ATTRIBUTES);
ippAddString (job_request, IPP_TAG_OPERATION, IPP_TAG_URI,
@@ -334,8 +330,6 @@ get_jobs_thread (GTask *task,
"requested-attributes", NULL, "job-hold-until");
job_response = cupsDoRequest (CUPS_HTTP_DEFAULT, job_request, "/");
- g_free (job_uri);
-
if (job_response != NULL)
{
attr = ippFindAttribute (job_response, "job-hold-until", IPP_TAG_ZERO);
@@ -345,7 +339,7 @@ get_jobs_thread (GTask *task,
if (auth_info_required == NULL)
{
- printer_uri = g_strdup_printf ("ipp://localhost/printers/%s", printer_name);
+ g_autofree gchar *printer_uri = g_strdup_printf ("ipp://localhost/printers/%s",
printer_name);
printer_request = ippNewRequest (IPP_GET_PRINTER_ATTRIBUTES);
ippAddString (printer_request, IPP_TAG_OPERATION, IPP_TAG_URI,
@@ -356,8 +350,6 @@ get_jobs_thread (GTask *task,
"requested-attributes", 1, NULL, (const char **) printer_attributes);
printer_response = cupsDoRequest (CUPS_HTTP_DEFAULT, printer_request, "/");
- g_free (printer_uri);
-
if (printer_response != NULL)
{
attr = ippFindAttribute (printer_response, "auth-info-required", IPP_TAG_ZERO);
@@ -389,7 +381,6 @@ get_jobs_thread (GTask *task,
g_strfreev (auth_info_required);
cupsFreeJobs (num_jobs, jobs);
- g_free (printer_name);
if (g_task_set_return_on_cancel (task, FALSE))
{
@@ -438,7 +429,6 @@ pp_printer_delete_dbus_cb (GObject *source_object,
gboolean result = FALSE;
g_autoptr(GError) error = NULL;
GTask *task = user_data;
- gchar *printer_name;
output = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source_object),
res,
@@ -447,7 +437,8 @@ pp_printer_delete_dbus_cb (GObject *source_object,
if (output != NULL)
{
- const gchar *ret_error;
+ g_autofree gchar *printer_name = NULL;
+ const gchar *ret_error;
g_object_get (g_task_get_source_object (task), "printer-name", &printer_name, NULL);
@@ -459,7 +450,6 @@ pp_printer_delete_dbus_cb (GObject *source_object,
g_task_return_boolean (task, result);
- g_free (printer_name);
g_variant_unref (output);
}
else
@@ -478,11 +468,12 @@ pp_printer_delete_cb (GObject *source_object,
GDBusConnection *bus;
g_autoptr(GError) error = NULL;
GTask *task = user_data;
- gchar *printer_name;
bus = g_bus_get_finish (res, &error);
if (bus != NULL)
{
+ g_autofree gchar *printer_name = NULL;
+
g_object_get (g_task_get_source_object (task),
"printer-name", &printer_name,
NULL);
@@ -499,8 +490,6 @@ pp_printer_delete_cb (GObject *source_object,
g_task_get_cancellable (task),
pp_printer_delete_dbus_cb,
task);
-
- g_free (printer_name);
}
else
{
@@ -556,17 +545,17 @@ print_file_thread (GTask *task,
gpointer task_data,
GCancellable *cancellable)
{
- PpPrinter *self = PP_PRINTER (source_object);
- PrintFileData *print_file_data;
- cups_ptype_t type = 0;
- cups_dest_t *dest = NULL;
- const gchar *printer_type = NULL;
- gboolean ret = FALSE;
- gchar *printer_name = NULL;
- gchar *printer_uri = NULL;
- gchar *resource = NULL;
- ipp_t *response = NULL;
- ipp_t *request;
+ PpPrinter *self = PP_PRINTER (source_object);
+ PrintFileData *print_file_data;
+ cups_ptype_t type = 0;
+ cups_dest_t *dest = NULL;
+ const gchar *printer_type = NULL;
+ gboolean ret = FALSE;
+ g_autofree gchar *printer_name = NULL;
+ g_autofree gchar *printer_uri = NULL;
+ g_autofree gchar *resource = NULL;
+ ipp_t *response = NULL;
+ ipp_t *request;
g_object_get (self, "printer-name", &printer_name, NULL);
dest = cupsGetNamedDest (CUPS_HTTP_DEFAULT, printer_name, NULL);
@@ -613,10 +602,6 @@ print_file_thread (GTask *task,
ippDelete (response);
}
- g_free (printer_name);
- g_free (printer_uri);
- g_free (resource);
-
if (g_task_set_return_on_cancel (task, FALSE))
{
g_task_return_boolean (task, ret);
diff --git a/panels/printers/pp-samba.c b/panels/printers/pp-samba.c
index 8f37a8ad2..80add734b 100644
--- a/panels/printers/pp-samba.c
+++ b/panels/printers/pp-samba.c
@@ -282,11 +282,8 @@ list_dir (SMBCCTX *smb_context,
while (dir && (dirent = smbclient_readdir (smb_context, dir)))
{
- gchar *device_name;
- gchar *device_uri;
- gchar *subdirname = NULL;
- gchar *subpath = NULL;
- gchar *uri;
+ g_autofree gchar *subdirname = NULL;
+ g_autofree gchar *subpath = NULL;
if (dirent->smbc_type == SMBC_WORKGROUP)
{
@@ -302,6 +299,10 @@ list_dir (SMBCCTX *smb_context,
if (dirent->smbc_type == SMBC_PRINTER_SHARE)
{
+ g_autofree gchar *uri = NULL;
+ g_autofree gchar *device_name = NULL;
+ g_autofree gchar *device_uri = NULL;
+
uri = g_strdup_printf ("%s/%s", dirname, dirent->name);
device_uri = g_uri_escape_string (uri,
G_URI_RESERVED_CHARS_GENERIC_DELIMITERS
@@ -309,7 +310,7 @@ list_dir (SMBCCTX *smb_context,
FALSE);
device_name = g_strdup (dirent->name);
- device_name = g_strcanon (device_name, ALLOWED_CHARACTERS, '-');
+ g_strcanon (device_name, ALLOWED_CHARACTERS, '-');
device = g_object_new (PP_TYPE_PRINT_DEVICE,
"device-uri", device_uri,
@@ -321,10 +322,6 @@ list_dir (SMBCCTX *smb_context,
"host-name", dirname,
NULL);
- g_free (device_name);
- g_free (device_uri);
- g_free (uri);
-
data->devices->devices = g_list_append (data->devices->devices, device);
}
@@ -335,8 +332,6 @@ list_dir (SMBCCTX *smb_context,
subpath,
cancellable,
data);
- g_free (subdirname);
- g_free (subpath);
}
}
diff --git a/panels/printers/pp-utils.c b/panels/printers/pp-utils.c
index c0814444e..fbeb3c67e 100644
--- a/panels/printers/pp-utils.c
+++ b/panels/printers/pp-utils.c
@@ -111,17 +111,15 @@ get_tag_value (const gchar *tag_string, const gchar *tag_name)
static gchar *
normalize (const gchar *input_string)
{
- gchar *tmp = NULL;
- gchar *res = NULL;
gchar *result = NULL;
gint i, j = 0, k = -1;
if (input_string)
{
- tmp = g_strstrip (g_ascii_strdown (input_string, -1));
+ g_autofree gchar *tmp = g_strstrip (g_ascii_strdown (input_string, -1));
if (tmp)
{
- res = g_new (gchar, 2 * strlen (tmp));
+ g_autofree gchar *res = g_new (gchar, 2 * strlen (tmp));
for (i = 0; i < strlen (tmp); i++)
{
@@ -154,8 +152,6 @@ normalize (const gchar *input_string)
res[j] = '\0';
result = g_strdup (res);
- g_free (tmp);
- g_free (res);
}
}
@@ -263,11 +259,11 @@ printer_rename (const gchar *old_name,
cups_dest_t *dest = NULL;
cups_job_t *jobs = NULL;
GDBusConnection *bus;
- const char *printer_location = NULL;
- const char *printer_info = NULL;
- const char *printer_uri = NULL;
- const char *device_uri = NULL;
- const char *job_sheets = NULL;
+ const gchar *printer_location = NULL;
+ const gchar *printer_info = NULL;
+ const gchar *printer_uri = NULL;
+ const gchar *device_uri = NULL;
+ const gchar *job_sheets = NULL;
gboolean result = FALSE;
gboolean accepting = TRUE;
gboolean printer_paused = FALSE;
@@ -275,16 +271,16 @@ printer_rename (const gchar *old_name,
gboolean printer_shared = FALSE;
g_autoptr(GError) error = NULL;
http_t *http;
- gchar *ppd_link;
- gchar *ppd_filename = NULL;
+ g_autofree gchar *ppd_link = NULL;
+ g_autofree gchar *ppd_filename = NULL;
gchar **sheets = NULL;
gchar **users_allowed = NULL;
gchar **users_denied = NULL;
gchar **member_names = NULL;
- gchar *start_sheet = NULL;
- gchar *end_sheet = NULL;
- gchar *error_policy = NULL;
- gchar *op_policy = NULL;
+ const gchar *start_sheet = NULL;
+ const gchar *end_sheet = NULL;
+ g_autofree gchar *error_policy = NULL;
+ g_autofree gchar *op_policy = NULL;
ipp_t *request;
ipp_t *response;
gint i;
@@ -498,8 +494,6 @@ printer_rename (const gchar *old_name,
if (ppd_link)
{
g_unlink (ppd_link);
- g_free (ppd_link);
- g_free (ppd_filename);
}
num_dests = cupsGetDests (&dests);
@@ -525,8 +519,6 @@ printer_rename (const gchar *old_name,
printer_set_accepting_jobs (old_name, accepting, NULL);
cupsFreeDests (num_dests, dests);
- g_free (op_policy);
- g_free (error_policy);
if (sheets)
g_strfreev (sheets);
if (users_allowed)
@@ -1285,7 +1277,7 @@ get_ipp_attributes_func (gpointer user_data)
GIAData *data = (GIAData *) user_data;
ipp_t *request;
ipp_t *response = NULL;
- gchar *printer_uri;
+ g_autofree gchar *printer_uri = NULL;
char **requested_attrs = NULL;
gint i, j, length = 0;
@@ -1377,8 +1369,6 @@ get_ipp_attributes_func (gpointer user_data)
g_free (requested_attrs[i]);
g_free (requested_attrs);
- g_free (printer_uri);
-
get_ipp_attributes_cb (data);
return NULL;
@@ -1764,13 +1754,12 @@ get_ppds_attribute_func (gpointer user_data)
ppd_file_t *ppd_file;
ppd_attr_t *ppd_attr;
GPAData *data = (GPAData *) user_data;
- gchar *ppd_filename;
gint i;
data->result = g_new0 (gchar *, g_strv_length (data->ppds_names) + 1);
for (i = 0; data->ppds_names[i]; i++)
{
- ppd_filename = g_strdup (cupsGetServerPPD (CUPS_HTTP_DEFAULT, data->ppds_names[i]));
+ g_autofree gchar *ppd_filename = g_strdup (cupsGetServerPPD (CUPS_HTTP_DEFAULT, data->ppds_names[i]));
if (ppd_filename)
{
ppd_file = ppdOpenFile (ppd_filename);
@@ -1784,7 +1773,6 @@ get_ppds_attribute_func (gpointer user_data)
}
g_unlink (ppd_filename);
- g_free (ppd_filename);
}
}
@@ -1943,8 +1931,6 @@ get_ppd_names_async_dbus_scb (GObject *source_object,
{
GVariantIter *iter;
GVariant *item;
- gchar *driver;
- gchar *match;
for (j = 0; j < G_N_ELEMENTS (match_levels) && n < data->count; j++)
{
@@ -1954,8 +1940,10 @@ get_ppd_names_async_dbus_scb (GObject *source_object,
while ((item = g_variant_iter_next_value (iter)))
{
+ const gchar *driver, *match;
+
g_variant_get (item,
- "(ss)",
+ "(&s&s)",
&driver,
&match);
@@ -1980,8 +1968,6 @@ get_ppd_names_async_dbus_scb (GObject *source_object,
n++;
}
- g_free (driver);
- g_free (match);
g_variant_unref (item);
}
}
@@ -2186,11 +2172,7 @@ get_device_attributes_async_dbus_cb (GObject *source_object,
if (data->device_uri)
{
- gchar *key;
- gchar *value;
- gchar *number;
- gchar *endptr;
- gchar *suffix;
+ g_autofree gchar *suffix = NULL;
g_variant_get (devices_variant,
"a{ss}",
@@ -2198,16 +2180,20 @@ get_device_attributes_async_dbus_cb (GObject *source_object,
while ((item = g_variant_iter_next_value (iter)))
{
+ const gchar *key, *value;
+
g_variant_get (item,
- "{ss}",
+ "{&s&s}",
&key,
&value);
if (g_str_equal (value, data->device_uri))
{
- number = g_strrstr (key, ":");
+ gchar *number = g_strrstr (key, ":");
if (number != NULL)
{
+ gchar *endptr;
+
number++;
index = g_ascii_strtoll (number, &endptr, 10);
if (index == 0 && endptr == (number))
@@ -2215,8 +2201,6 @@ get_device_attributes_async_dbus_cb (GObject *source_object,
}
}
- g_free (key);
- g_free (value);
g_variant_unref (item);
}
@@ -2228,11 +2212,10 @@ get_device_attributes_async_dbus_cb (GObject *source_object,
while ((item = g_variant_iter_next_value (iter)))
{
- gchar *key;
- gchar *value;
+ const gchar *key, *value;
g_variant_get (item,
- "{ss}",
+ "{&s&s}",
&key,
&value);
@@ -2249,12 +2232,8 @@ get_device_attributes_async_dbus_cb (GObject *source_object,
}
}
- g_free (key);
- g_free (value);
g_variant_unref (item);
}
-
- g_free (suffix);
}
g_variant_unref (devices_variant);
@@ -2631,14 +2610,6 @@ get_all_ppds_func (gpointer user_data)
ipp_t *request;
ipp_t *response;
GList *list;
- const gchar *ppd_make_and_model;
- const gchar *ppd_device_id;
- const gchar *ppd_name;
- const gchar *ppd_product;
- const gchar *ppd_make;
- gchar *mfg;
- gchar *mfg_normalized;
- gchar *mdl;
gchar *manufacturer_display_name;
gint i, j;
@@ -2671,21 +2642,21 @@ get_all_ppds_func (gpointer user_data)
for (attr = ippFirstAttribute (response); attr != NULL; attr = ippNextAttribute (response))
{
+ const gchar *ppd_device_id = NULL;
+ const gchar *ppd_make_and_model = NULL;
+ const gchar *ppd_name = NULL;
+ const gchar *ppd_product = NULL;
+ const gchar *ppd_make = NULL;
+ g_autofree gchar *mdl = NULL;
+ g_autofree gchar *mfg = NULL;
+ g_autofree gchar *mfg_normalized = NULL;
+
while (attr != NULL && ippGetGroupTag (attr) != IPP_TAG_PRINTER)
attr = ippNextAttribute (response);
if (attr == NULL)
break;
- ppd_device_id = NULL;
- ppd_make_and_model = NULL;
- ppd_name = NULL;
- ppd_product = NULL;
- ppd_make = NULL;
- mfg = NULL;
- mfg_normalized = NULL;
- mdl = NULL;
-
while (attr != NULL && ippGetGroupTag (attr) == IPP_TAG_PRINTER)
{
if (g_strcmp0 (ippGetName (attr), "ppd-device-id") == 0 &&
@@ -2779,10 +2750,6 @@ get_all_ppds_func (gpointer user_data)
}
}
- g_free (mdl);
- g_free (mfg);
- g_free (mfg_normalized);
-
if (attr == NULL)
break;
}
@@ -2961,27 +2928,23 @@ ppd_list_free (PPDList *list)
gchar *
get_standard_manufacturers_name (const gchar *name)
{
- gchar *normalized_name;
- gchar *result = NULL;
+ g_autofree gchar *normalized_name = NULL;
gint i;
- if (name)
- {
- normalized_name = normalize (name);
+ if (name == NULL)
+ return NULL;
- for (i = 0; i < G_N_ELEMENTS (manufacturers_names); i++)
+ normalized_name = normalize (name);
+
+ for (i = 0; i < G_N_ELEMENTS (manufacturers_names); i++)
+ {
+ if (g_strcmp0 (manufacturers_names[i].normalized_name, normalized_name) == 0)
{
- if (g_strcmp0 (manufacturers_names[i].normalized_name, normalized_name) == 0)
- {
- result = g_strdup (manufacturers_names[i].display_name);
- break;
- }
+ return g_strdup (manufacturers_names[i].display_name);
}
-
- g_free (normalized_name);
}
- return result;
+ return NULL;
}
typedef struct
@@ -3307,7 +3270,7 @@ typedef struct
} GCDData;
static gint
-get_suffix_index (gchar *string)
+get_suffix_index (const gchar *string)
{
gchar *number;
gchar *endptr;
@@ -3361,21 +3324,19 @@ get_cups_devices_async_dbus_cb (GObject *source_object,
{
GVariantIter *iter;
GVariant *item;
- gchar *key;
- gchar *value;
gint index = -1, max_index = -1, i;
g_variant_get (devices_variant, "a{ss}", &iter);
while ((item = g_variant_iter_next_value (iter)))
{
- g_variant_get (item, "{ss}", &key, &value);
+ const gchar *key, *value;
+
+ g_variant_get (item, "{&s&s}", &key, &value);
index = get_suffix_index (key);
if (index > max_index)
max_index = index;
- g_free (key);
- g_free (value);
g_variant_unref (item);
}
@@ -3387,7 +3348,9 @@ get_cups_devices_async_dbus_cb (GObject *source_object,
g_variant_get (devices_variant, "a{ss}", &iter);
while ((item = g_variant_iter_next_value (iter)))
{
- g_variant_get (item, "{ss}", &key, &value);
+ const gchar *key, *value;
+
+ g_variant_get (item, "{&s&s}", &key, &value);
index = get_suffix_index (key);
if (index >= 0)
@@ -3419,8 +3382,6 @@ get_cups_devices_async_dbus_cb (GObject *source_object,
g_object_set (devices[index], "acquisition-method",
ACQUISITION_METHOD_DEFAULT_CUPS_SERVER, NULL);
}
- g_free (key);
- g_free (value);
g_variant_unref (item);
}
@@ -3459,9 +3420,9 @@ get_cups_devices_async_dbus_cb (GObject *source_object,
{
if (!g_cancellable_is_cancelled (data->cancellable))
{
- GVariantBuilder *include_scheme_builder = NULL;
- GVariantBuilder *exclude_scheme_builder = NULL;
- gchar *backend_name;
+ GVariantBuilder *include_scheme_builder = NULL;
+ GVariantBuilder *exclude_scheme_builder = NULL;
+ g_autofree gchar *backend_name = NULL;
backend_name = data->backend_list->data;
@@ -3480,7 +3441,6 @@ get_cups_devices_async_dbus_cb (GObject *source_object,
exclude_scheme_builder = create_other_backends_array ();
}
- g_free (backend_name);
data->backend_list = g_list_remove_link (data->backend_list, data->backend_list);
g_dbus_connection_call (G_DBUS_CONNECTION (g_object_ref (source_object)),
@@ -3542,7 +3502,7 @@ get_cups_devices_async (GCancellable *cancellable,
GVariantBuilder include_scheme_builder;
GCDData *data;
g_autoptr(GError) error = NULL;
- gchar *backend_name;
+ g_autofree gchar *backend_name = NULL;
bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
if (!bus)
@@ -3564,7 +3524,6 @@ get_cups_devices_async (GCancellable *cancellable,
g_variant_builder_init (&include_scheme_builder, G_VARIANT_TYPE ("as"));
g_variant_builder_add (&include_scheme_builder, "s", backend_name);
- g_free (backend_name);
data->backend_list = g_list_remove_link (data->backend_list, data->backend_list);
g_dbus_connection_call (bus,
@@ -3665,9 +3624,7 @@ canonicalize_device_name (GList *device_names,
gboolean already_present;
GList *iter;
gsize len;
- gchar *name = NULL;
- gchar *new_name;
- gchar *lower_name;
+ g_autofree gchar *name = NULL;
gchar *occurrence;
gint name_index, j;
static const char * const residues[] = {
@@ -3725,7 +3682,7 @@ canonicalize_device_name (GList *device_names,
/* Remove common strings found in driver names */
for (j = 0; j < G_N_ELEMENTS (residues); j++)
{
- lower_name = g_ascii_strdown (name, -1);
+ g_autofree gchar *lower_name = g_ascii_strdown (name, -1);
occurrence = g_strrstr (lower_name, residues[j]);
if (occurrence != NULL)
@@ -3733,8 +3690,6 @@ canonicalize_device_name (GList *device_names,
occurrence[0] = '\0';
name[strlen (lower_name)] = '\0';
}
-
- g_free (lower_name);
}
/* Remove trailing "-" */
@@ -3756,8 +3711,10 @@ canonicalize_device_name (GList *device_names,
name_index = 2;
already_present = FALSE;
- do
+ while (TRUE)
{
+ g_autofree gchar *new_name = NULL;
+
if (already_present)
{
new_name = g_strdup_printf ("%s-%d", name, name_index);
@@ -3787,14 +3744,9 @@ canonicalize_device_name (GList *device_names,
already_present = TRUE;
}
- if (already_present)
- g_free (new_name);
-
- } while (already_present);
-
- g_free (name);
-
- return new_name;
+ if (!already_present)
+ return g_steal_pointer (&new_name);
+ }
}
void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]