printers: Use g_autoptr with strings

This commit is contained in:
Robert Ancell 2018-06-26 11:52:41 +12:00
parent 9a2c72e231
commit e9b9966e7d
15 changed files with 243 additions and 385 deletions

View file

@ -700,8 +700,8 @@ on_printer_deleted (PpPrinterEntry *printer_entry,
{ {
CcPrintersPanel *self = (CcPrintersPanel*) user_data; CcPrintersPanel *self = (CcPrintersPanel*) user_data;
GtkLabel *label; GtkLabel *label;
gchar *notification_message; g_autofree gchar *notification_message = NULL;
gchar *printer_name; g_autofree gchar *printer_name = NULL;
gtk_widget_hide (GTK_WIDGET (printer_entry)); 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_builder_get_object (self->builder, "notification-label");
gtk_label_set_label (label, notification_message); gtk_label_set_label (label, notification_message);
g_free (notification_message);
self->deleted_printer_name = g_strdup (printer_name); self->deleted_printer_name = g_strdup (printer_name);
g_free (printer_name);
gtk_revealer_set_reveal_child (self->notification, TRUE); gtk_revealer_set_reveal_child (self->notification, TRUE);
@ -1155,11 +1152,11 @@ filter_function (GtkListBoxRow *row,
CcPrintersPanel *self = (CcPrintersPanel*) user_data; CcPrintersPanel *self = (CcPrintersPanel*) user_data;
GtkWidget *search_entry; GtkWidget *search_entry;
gboolean retval; gboolean retval;
gchar *search; g_autofree gchar *search = NULL;
gchar *name; g_autofree gchar *name = NULL;
gchar *location; g_autofree gchar *location = NULL;
gchar *printer_name; g_autofree gchar *printer_name = NULL;
gchar *printer_location; g_autofree gchar *printer_location = NULL;
search_entry = (GtkWidget*) search_entry = (GtkWidget*)
gtk_builder_get_object (self->builder, "search-entry"); 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); name = cc_util_normalize_casefold_and_unaccent (printer_name);
location = cc_util_normalize_casefold_and_unaccent (printer_location); 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))); search = cc_util_normalize_casefold_and_unaccent (gtk_entry_get_text (GTK_ENTRY (search_entry)));
retval = strstr (name, search) != NULL; retval = strstr (name, search) != NULL;
if (location != NULL) if (location != NULL)
retval = retval || (strstr (location, search) != NULL); retval = retval || (strstr (location, search) != NULL);
g_free (search);
g_free (name);
g_free (location);
return retval; return retval;
} }

View file

@ -125,15 +125,13 @@ printer_name_changed (GtkEditable *editable,
{ {
PpDetailsDialog *self = (PpDetailsDialog *) user_data; PpDetailsDialog *self = (PpDetailsDialog *) user_data;
const gchar *name; const gchar *name;
gchar *title; g_autofree gchar *title = NULL;
name = gtk_entry_get_text (GTK_ENTRY (self->printer_name_entry)); name = gtk_entry_get_text (GTK_ENTRY (self->printer_name_entry));
/* Translators: This is the title of the dialog. %s is the printer name. */ /* Translators: This is the title of the dialog. %s is the printer name. */
title = g_strdup_printf (_("%s Details"), name); title = g_strdup_printf (_("%s Details"), name);
gtk_label_set_label (self->dialog_title, title); gtk_label_set_label (self->dialog_title, title);
g_free (title);
} }
static void static void
@ -219,7 +217,7 @@ ppd_selection_dialog_response_cb (GtkDialog *dialog,
if (response_id == GTK_RESPONSE_OK) 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); 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); g_clear_pointer (&self->ppd_file_name, g_free);
self->ppd_file_name = g_strdup (ppd_name); self->ppd_file_name = g_strdup (ppd_name);
} }
g_free (ppd_name);
} }
pp_ppd_selection_dialog_free (self->pp_ppd_selection_dialog); pp_ppd_selection_dialog_free (self->pp_ppd_selection_dialog);
@ -259,8 +255,8 @@ static void
select_ppd_in_dialog (GtkButton *button, select_ppd_in_dialog (GtkButton *button,
PpDetailsDialog *self) PpDetailsDialog *self)
{ {
gchar *device_id = NULL; g_autofree gchar *device_id = NULL;
gchar *manufacturer = NULL; g_autofree gchar *manufacturer = NULL;
g_clear_pointer (&self->ppd_file_name, g_free); g_clear_pointer (&self->ppd_file_name, g_free);
self->ppd_file_name = g_strdup (cupsGetPPD (self->printer_name)); self->ppd_file_name = g_strdup (cupsGetPPD (self->printer_name));
@ -301,9 +297,6 @@ select_ppd_in_dialog (GtkButton *button,
manufacturer, manufacturer,
ppd_selection_dialog_response_cb, ppd_selection_dialog_response_cb,
self); 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) 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)); ppd_filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
@ -346,8 +339,6 @@ select_ppd_manually (GtkButton *button,
set_ppd_cb, set_ppd_cb,
self); self);
} }
g_free (ppd_filename);
} }
gtk_widget_destroy (dialog); gtk_widget_destroy (dialog);
@ -410,8 +401,8 @@ pp_details_dialog_new (GtkWindow *parent,
gboolean sensitive) gboolean sensitive)
{ {
PpDetailsDialog *self; PpDetailsDialog *self;
gchar *title; g_autofree gchar *title = NULL;
gchar *printer_url; g_autofree gchar *printer_url = NULL;
self = g_object_new (PP_DETAILS_DIALOG_TYPE, self = g_object_new (PP_DETAILS_DIALOG_TYPE,
"transient-for", parent, "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. */ /* Translators: This is the title of the dialog. %s is the printer name. */
title = g_strdup_printf (_("%s Details"), printer_name); title = g_strdup_printf (_("%s Details"), printer_name);
gtk_label_set_label (self->dialog_title, title); 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); 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); 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_name_entry), printer_name);
gtk_entry_set_text (GTK_ENTRY (self->printer_location_entry), printer_location); gtk_entry_set_text (GTK_ENTRY (self->printer_location_entry), printer_location);

View file

@ -162,7 +162,7 @@ line_split (gchar *line)
gboolean in_word = FALSE; gboolean in_word = FALSE;
gchar **words = NULL; gchar **words = NULL;
gchar **result = NULL; gchar **result = NULL;
gchar *buffer = NULL; g_autofree gchar *buffer = NULL;
gchar ch; gchar ch;
gint n = 0; gint n = 0;
gint i, j = 0, k = 0; gint i, j = 0, k = 0;
@ -233,7 +233,6 @@ line_split (gchar *line)
result = g_strdupv (words); result = g_strdupv (words);
g_strfreev (words); g_strfreev (words);
g_free (buffer);
return result; return result;
} }
@ -275,7 +274,6 @@ _pp_host_get_snmp_devices_thread (GTask *task,
if (exit_status == 0 && stdout_string) if (exit_status == 0 && stdout_string)
{ {
g_auto(GStrv) printer_informations = NULL; g_auto(GStrv) printer_informations = NULL;
g_autofree gchar *device_name = NULL;
gint length; gint length;
printer_informations = line_split (stdout_string); printer_informations = line_split (stdout_string);
@ -283,8 +281,10 @@ _pp_host_get_snmp_devices_thread (GTask *task,
if (length >= 4) if (length >= 4)
{ {
g_autofree gchar *device_name = NULL;
device_name = g_strdup (printer_informations[3]); 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; is_network_device = g_strcmp0 (printer_informations[0], "network") == 0;
device = g_object_new (PP_TYPE_PRINT_DEVICE, device = g_object_new (PP_TYPE_PRINT_DEVICE,

View file

@ -231,17 +231,16 @@ set_cb (GtkTreeModel *model,
gpointer data) gpointer data)
{ {
struct ComboSet *set_data = data; struct ComboSet *set_data = data;
gboolean found; g_autofree gchar *value = NULL;
char *value;
gtk_tree_model_get (model, iter, VALUE_COLUMN, &value, -1); gtk_tree_model_get (model, iter, VALUE_COLUMN, &value, -1);
found = (strcmp (value, set_data->value) == 0); if (strcmp (value, set_data->value) == 0)
g_free (value); {
if (found)
gtk_combo_box_set_active_iter (set_data->combo, iter); gtk_combo_box_set_active_iter (set_data->combo, iter);
return TRUE;
}
return found; return FALSE;
} }
static void static void
@ -374,7 +373,6 @@ construct_widget (PpIPPOptionWidget *self)
{ {
gboolean trivial_option = FALSE; gboolean trivial_option = FALSE;
gboolean result = FALSE; gboolean result = FALSE;
gchar *value;
gint i; gint i;
if (self->option_supported) if (self->option_supported)
@ -414,12 +412,13 @@ construct_widget (PpIPPOptionWidget *self)
for (i = 0; i < self->option_supported->num_of_values; i++) 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); value = g_strdup_printf ("%d", self->option_supported->attribute_values[i].integer_value);
combo_box_append (self->combo, combo_box_append (self->combo,
ipp_choice_translate (self->option_name, ipp_choice_translate (self->option_name,
value), value),
value); value);
g_free (value);
} }
gtk_box_pack_start (GTK_BOX (self), self->combo, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (self), self->combo, FALSE, FALSE, 0);
@ -464,8 +463,6 @@ static void
update_widget_real (PpIPPOptionWidget *self) update_widget_real (PpIPPOptionWidget *self)
{ {
IPPAttribute *attr = NULL; IPPAttribute *attr = NULL;
gchar *value;
gchar *attr_name;
if (self->option_default) if (self->option_default)
{ {
@ -476,10 +473,9 @@ update_widget_real (PpIPPOptionWidget *self)
} }
else if (self->ipp_attribute) 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)); attr = ipp_attribute_copy (g_hash_table_lookup (self->ipp_attribute, attr_name));
g_free (attr_name);
g_hash_table_unref (self->ipp_attribute); g_hash_table_unref (self->ipp_attribute);
self->ipp_attribute = NULL; self->ipp_attribute = NULL;
} }
@ -505,15 +501,13 @@ update_widget_real (PpIPPOptionWidget *self)
if (attr && attr->num_of_values > 0 && if (attr && attr->num_of_values > 0 &&
attr->attribute_type == IPP_ATTRIBUTE_TYPE_INTEGER) 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); combo_box_set (self->combo, value);
g_free (value);
} }
else 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); combo_box_set (self->combo, value);
g_free (value);
} }
g_signal_handlers_unblock_by_func (self->combo, combo_changed_cb, self); g_signal_handlers_unblock_by_func (self->combo, combo_changed_cb, self);

View file

@ -291,7 +291,7 @@ _pp_job_get_attributes_thread (GTask *task,
gchar **attributes_names = task_data; gchar **attributes_names = task_data;
ipp_t *request; ipp_t *request;
ipp_t *response = NULL; ipp_t *response = NULL;
gchar *job_uri; g_autofree gchar *job_uri = NULL;
gint i, j, length = 0, n_attrs = 0; gint i, j, length = 0, n_attrs = 0;
job_uri = g_strdup_printf ("ipp://localhost/jobs/%d", self->id); 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); attributes = g_variant_builder_end (&builder);
} }
g_free (job_uri);
g_task_return_pointer (task, attributes, (GDestroyNotify) g_variant_unref); 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; gchar **auth_info = task_data;
ipp_t *request; ipp_t *request;
ipp_t *response = NULL; ipp_t *response = NULL;
gchar *job_uri;
gint length; gint length;
if (auth_info != NULL) 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); length = g_strv_length (auth_info);
@ -450,8 +448,6 @@ _pp_job_authenticate_thread (GTask *task,
if (response != NULL) if (response != NULL)
ippDelete (response); ippDelete (response);
g_free (job_uri);
} }
g_task_return_boolean (task, result); g_task_return_boolean (task, result);

View file

@ -327,7 +327,6 @@ update_jobs_list_cb (GObject *source_object,
GList *jobs, *l; GList *jobs, *l;
PpJob *job; PpJob *job;
gchar **auth_info_required = NULL; gchar **auth_info_required = NULL;
gchar *text;
gint num_of_jobs, num_of_auth_jobs = 0; gint num_of_jobs, num_of_auth_jobs = 0;
g_list_store_remove_all (self->store); 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")); infobar = GTK_WIDGET (gtk_builder_get_object (GTK_BUILDER (self->builder), "authentication-infobar"));
if (num_of_auth_jobs > 0) 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")); 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. */ /* 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); 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); gtk_label_set_text (GTK_LABEL (label), text);
g_free (text);
gtk_widget_show (infobar); gtk_widget_show (infobar);
} }
@ -559,9 +559,9 @@ pp_jobs_dialog_new (GtkWindow *parent,
GtkWidget *widget; GtkWidget *widget;
g_autoptr(GError) error = NULL; g_autoptr(GError) error = NULL;
gchar *objects[] = { "jobs-dialog", "authentication_popover", NULL }; gchar *objects[] = { "jobs-dialog", "authentication_popover", NULL };
gchar *text; g_autofree gchar *text = NULL;
guint builder_result; guint builder_result;
gchar *title; g_autofree gchar *title = NULL;
self = g_new0 (PpJobsDialog, 1); 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 */ /* 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); title = g_strdup_printf (C_("Printer jobs dialog title", "%s — Active Jobs"), printer_name);
gtk_window_set_title (GTK_WINDOW (self->dialog), title); gtk_window_set_title (GTK_WINDOW (self->dialog), title);
g_free (title);
/* Translators: The printer needs authentication info to print. */ /* Translators: The printer needs authentication info to print. */
text = g_strdup_printf (_("Enter credentials to print from %s."), printer_name); 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")); widget = GTK_WIDGET (gtk_builder_get_object (GTK_BUILDER (self->builder), "authentication-label"));
gtk_label_set_text (GTK_LABEL (widget), text); gtk_label_set_text (GTK_LABEL (widget), text);
g_free (text);
self->listbox = GTK_LIST_BOX (gtk_builder_get_object (self->builder, "jobs-listbox")); self->listbox = GTK_LIST_BOX (gtk_builder_get_object (self->builder, "jobs-listbox"));
gtk_list_box_set_header_func (self->listbox, gtk_list_box_set_header_func (self->listbox,

View file

@ -206,8 +206,8 @@ _pp_maintenance_command_execute_thread (GTask *task,
{ {
ipp_t *request; ipp_t *request;
ipp_t *response = NULL; ipp_t *response = NULL;
gchar *printer_uri; g_autofree gchar *printer_uri = NULL;
gchar *file_name = NULL; g_autofree gchar *file_name = NULL;
int fd = -1; int fd = -1;
printer_uri = g_strdup_printf ("ipp://localhost/printers/%s", printer_uri = g_strdup_printf ("ipp://localhost/printers/%s",
@ -249,9 +249,6 @@ _pp_maintenance_command_execute_thread (GTask *task,
ippDelete (response); ippDelete (response);
} }
} }
g_free (file_name);
g_free (printer_uri);
} }
else else
{ {
@ -302,8 +299,7 @@ _pp_maintenance_command_is_supported (const gchar *printer_name,
gboolean is_supported = FALSE; gboolean is_supported = FALSE;
ipp_t *request; ipp_t *request;
ipp_t *response = NULL; ipp_t *response = NULL;
gchar *printer_uri; g_autofree gchar *printer_uri = NULL;
gchar *command_lowercase;
GPtrArray *available_commands = NULL; GPtrArray *available_commands = NULL;
int i; int i;
@ -342,7 +338,7 @@ _pp_maintenance_command_is_supported (const gchar *printer_name,
if (available_commands != NULL) 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) for (i = 0; i < available_commands->len; ++i)
{ {
const gchar *available_command = g_ptr_array_index (available_commands, 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_ptr_array_free (available_commands, TRUE);
} }
g_free (printer_uri);
return is_supported; return is_supported;
} }

View file

@ -372,22 +372,21 @@ on_authentication_required (PpHost *host,
gpointer user_data) gpointer user_data)
{ {
PpNewPrinterDialog *self = 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_subtitle (GTK_HEADER_BAR (WID ("headerbar")), NULL);
gtk_header_bar_set_title (GTK_HEADER_BAR (WID ("headerbar")), _("Unlock Print Server")); gtk_header_bar_set_title (GTK_HEADER_BAR (WID ("headerbar")), _("Unlock Print Server"));
g_object_get (G_OBJECT (host), "hostname", &hostname, NULL); g_object_get (G_OBJECT (host), "hostname", &hostname, NULL);
/* Translators: Samba server needs authentication of the user to show list of its printers. */ /* Translators: Samba server needs authentication of the user to show list of its printers. */
text = g_strdup_printf (_("Unlock %s."), hostname); title = g_strdup_printf (_("Unlock %s."), hostname);
gtk_label_set_text (GTK_LABEL (WID ("authentication-title")), text); gtk_label_set_text (GTK_LABEL (WID ("authentication-title")), title);
g_free (text);
/* Translators: Samba server needs authentication of the user to show list of its printers. */ /* 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); text = g_strdup_printf (_("Enter username and password to view printers on %s."), hostname);
gtk_label_set_text (GTK_LABEL (WID ("authentication-text")), text); gtk_label_set_text (GTK_LABEL (WID ("authentication-text")), text);
g_free (hostname);
g_free (text);
go_to_page (self, AUTHENTICATION_PAGE); go_to_page (self, AUTHENTICATION_PAGE);
@ -686,17 +685,14 @@ add_device_to_list (PpNewPrinterDialog *self,
{ {
PpPrintDevice *store_device; PpPrintDevice *store_device;
GList *original_names_list = NULL; GList *original_names_list = NULL;
gchar *canonicalized_name = NULL;
gchar *host_name;
gint acquisistion_method; gint acquisistion_method;
if (device) if (device)
{ {
if (pp_print_device_get_host_name (device) == NULL) 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_object_set (device, "host-name", host_name, NULL);
g_free (host_name);
} }
acquisistion_method = pp_print_device_get_acquisition_method (device); 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_JETDIRECT ||
acquisistion_method == ACQUISITION_METHOD_LPD))) acquisistion_method == ACQUISITION_METHOD_LPD)))
{ {
g_autofree gchar *canonicalized_name = NULL;
g_object_set (device, g_object_set (device,
"device-original-name", pp_print_device_get_device_name (device), "device-original-name", pp_print_device_get_device_name (device),
NULL); NULL);
@ -733,8 +731,6 @@ add_device_to_list (PpNewPrinterDialog *self,
"device-name", canonicalized_name, "device-name", canonicalized_name,
NULL); NULL);
g_free (canonicalized_name);
if (pp_print_device_get_acquisition_method (device) == ACQUISITION_METHOD_DEFAULT_CUPS_SERVER) 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)); self->local_cups_devices = g_list_append (self->local_cups_devices, g_object_ref (device));
else else
@ -1384,7 +1380,7 @@ parse_uri (const gchar *uri,
gint *port) gint *port)
{ {
const gchar *tmp = NULL; const gchar *tmp = NULL;
gchar *resulting_host = NULL; g_autofree gchar *resulting_host = NULL;
gchar *position; gchar *position;
*port = PP_HOST_UNSET_PORT; *port = PP_HOST_UNSET_PORT;
@ -1424,8 +1420,6 @@ parse_uri (const gchar *uri,
G_URI_RESERVED_CHARS_GENERIC_DELIMITERS G_URI_RESERVED_CHARS_GENERIC_DELIMITERS
G_URI_RESERVED_CHARS_SUBCOMPONENT_DELIMITERS); G_URI_RESERVED_CHARS_SUBCOMPONENT_DELIMITERS);
g_free (resulting_host);
return TRUE; return TRUE;
} }
@ -1523,9 +1517,7 @@ search_address (const gchar *text,
gboolean subfound; gboolean subfound;
gboolean next_set; gboolean next_set;
gboolean cont; gboolean cont;
gchar *lowercase_name; g_autofree gchar *lowercase_text = NULL;
gchar *lowercase_location;
gchar *lowercase_text;
gchar **words; gchar **words;
gint words_length = 0; gint words_length = 0;
gint i; gint i;
@ -1533,7 +1525,6 @@ search_address (const gchar *text,
lowercase_text = g_ascii_strdown (text, -1); lowercase_text = g_ascii_strdown (text, -1);
words = g_strsplit_set (lowercase_text, " ", -1); words = g_strsplit_set (lowercase_text, " ", -1);
g_free (lowercase_text);
if (words) if (words)
{ {
@ -1542,6 +1533,9 @@ search_address (const gchar *text,
cont = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (self->store), &iter); cont = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (self->store), &iter);
while (cont) while (cont)
{ {
g_autofree gchar *lowercase_name = NULL;
g_autofree gchar *lowercase_location = NULL;
gtk_tree_model_get (GTK_TREE_MODEL (self->store), &iter, gtk_tree_model_get (GTK_TREE_MODEL (self->store), &iter,
DEVICE_COLUMN, &device, DEVICE_COLUMN, &device,
-1); -1);
@ -1567,8 +1561,6 @@ search_address (const gchar *text,
DEVICE_VISIBLE_COLUMN, subfound, DEVICE_VISIBLE_COLUMN, subfound,
-1); -1);
g_free (lowercase_location);
g_free (lowercase_name);
g_object_unref (device); g_object_unref (device);
cont = gtk_tree_model_iter_next (GTK_TREE_MODEL (self->store), &iter); cont = gtk_tree_model_iter_next (GTK_TREE_MODEL (self->store), &iter);
@ -1715,7 +1707,6 @@ set_device (PpNewPrinterDialog *self,
GtkTreeIter *iter) GtkTreeIter *iter)
{ {
GtkTreeIter titer; GtkTreeIter titer;
gchar *description;
gint acquisition_method; gint acquisition_method;
if (device != NULL) if (device != NULL)
@ -1732,6 +1723,8 @@ set_device (PpNewPrinterDialog *self,
acquisition_method == ACQUISITION_METHOD_SAMBA_HOST || acquisition_method == ACQUISITION_METHOD_SAMBA_HOST ||
acquisition_method == ACQUISITION_METHOD_SAMBA)) acquisition_method == ACQUISITION_METHOD_SAMBA))
{ {
g_autofree gchar *description = NULL;
description = get_local_scheme_description_from_uri (pp_print_device_get_device_uri (device)); description = get_local_scheme_description_from_uri (pp_print_device_get_device_uri (device));
if (description == NULL) if (description == NULL)
{ {
@ -1758,8 +1751,6 @@ set_device (PpNewPrinterDialog *self,
DEVICE_VISIBLE_COLUMN, TRUE, DEVICE_VISIBLE_COLUMN, TRUE,
DEVICE_COLUMN, device, DEVICE_COLUMN, device,
-1); -1);
g_free (description);
} }
else if (pp_print_device_is_authenticated_server (device) && else if (pp_print_device_is_authenticated_server (device) &&
pp_print_device_get_host_name (device) != NULL) pp_print_device_get_host_name (device) != NULL)
@ -1886,9 +1877,8 @@ cell_data_func (GtkTreeViewColumn *tree_column,
{ {
PpNewPrinterDialog *self = user_data; PpNewPrinterDialog *self = user_data;
gboolean selected = FALSE; gboolean selected = FALSE;
gchar *name = NULL; g_autofree gchar *name = NULL;
gchar *description = NULL; g_autofree gchar *description = NULL;
gchar *text;
selected = gtk_tree_selection_iter_is_selected (gtk_tree_view_get_selection (self->treeview), iter); 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) if (name != NULL)
{ {
g_autofree gchar *text = NULL;
if (description != NULL) if (description != NULL)
{ {
if (selected) if (selected)
@ -1919,12 +1911,7 @@ cell_data_func (GtkTreeViewColumn *tree_column,
g_object_set (G_OBJECT (cell), g_object_set (G_OBJECT (cell),
"markup", text, "markup", text,
NULL); NULL);
g_free (text);
} }
g_free (name);
g_free (description);
} }
static void static void
@ -2026,7 +2013,6 @@ ppd_selection_cb (GtkDialog *_dialog,
GList *original_names_list = NULL; GList *original_names_list = NULL;
gchar *ppd_name; gchar *ppd_name;
gchar *ppd_display_name; gchar *ppd_display_name;
gchar *printer_name;
guint window_id = 0; guint window_id = 0;
gint acquisition_method; gint acquisition_method;
@ -2044,6 +2030,8 @@ ppd_selection_cb (GtkDialog *_dialog,
acquisition_method == ACQUISITION_METHOD_LPD) && acquisition_method == ACQUISITION_METHOD_LPD) &&
ppd_display_name != NULL) ppd_display_name != NULL)
{ {
g_autofree gchar *printer_name = NULL;
g_object_set (self->new_device, g_object_set (self->new_device,
"device-name", ppd_display_name, "device-name", ppd_display_name,
"device-original-name", ppd_display_name, "device-original-name", ppd_display_name,
@ -2067,8 +2055,6 @@ ppd_selection_cb (GtkDialog *_dialog,
"device-name", printer_name, "device-name", printer_name,
"device-original-name", printer_name, "device-original-name", printer_name,
NULL); NULL);
g_free (printer_name);
} }
emit_pre_response (self, emit_pre_response (self,

View file

@ -485,15 +485,15 @@ get_ppd_item_from_output (GVariant *output)
{ {
GVariantIter *iter; GVariantIter *iter;
GVariant *item; GVariant *item;
gchar *driver;
gchar *match;
for (j = 0; j < G_N_ELEMENTS (match_levels) && !ppd_item; j++) for (j = 0; j < G_N_ELEMENTS (match_levels) && !ppd_item; j++)
{ {
g_variant_get (array, "a(ss)", &iter); g_variant_get (array, "a(ss)", &iter);
while ((item = g_variant_iter_next_value (iter)) && !ppd_item) 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])) if (g_str_equal (match, match_levels[j]))
{ {
ppd_item = g_new0 (PPDName, 1); 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; ppd_item->ppd_match_level = PPD_NO_MATCH;
} }
g_free (driver);
g_free (match);
g_variant_unref (item); g_variant_unref (item);
} }
} }

View file

@ -871,7 +871,7 @@ test_page_cb (GtkButton *button,
"/usr/local/share/cups", "/usr/local/share/cups",
NULL }; NULL };
const gchar *datadir = NULL; const gchar *datadir = NULL;
gchar *filename = NULL; g_autofree gchar *filename = NULL;
datadir = getenv ("CUPS_DATADIR"); datadir = getenv ("CUPS_DATADIR");
if (datadir != NULL) if (datadir != NULL)
@ -896,8 +896,6 @@ test_page_cb (GtkButton *button,
NULL, NULL,
print_test_page_cb, print_test_page_cb,
NULL); NULL);
g_free (filename);
} }
else else
{ {

View file

@ -289,17 +289,17 @@ set_cb (GtkTreeModel *model,
gpointer data) gpointer data)
{ {
struct ComboSet *set_data = data; struct ComboSet *set_data = data;
gboolean found; g_autofree gchar *value = NULL;
char *value;
gtk_tree_model_get (model, iter, VALUE_COLUMN, &value, -1); gtk_tree_model_get (model, iter, VALUE_COLUMN, &value, -1);
found = (strcmp (value, set_data->value) == 0);
g_free (value);
if (found) if (strcmp (value, set_data->value) == 0)
{
gtk_combo_box_set_active_iter (set_data->combo, iter); gtk_combo_box_set_active_iter (set_data->combo, iter);
return TRUE;
}
return found; return FALSE;
} }
static void static void
@ -467,7 +467,6 @@ update_widget_real (PpPPDOptionWidget *self)
{ {
ppd_option_t *option = NULL, *iter; ppd_option_t *option = NULL, *iter;
ppd_file_t *ppd_file; ppd_file_t *ppd_file;
gchar *value = NULL;
gint i; gint i;
if (self->option) if (self->option)
@ -504,6 +503,8 @@ update_widget_real (PpPPDOptionWidget *self)
if (option) if (option)
{ {
g_autofree gchar *value = NULL;
for (i = 0; i < option->num_choices; i++) for (i = 0; i < option->num_choices; i++)
if (option->choices[i].marked) if (option->choices[i].marked)
value = g_strdup (option->choices[i].choice); value = g_strdup (option->choices[i].choice);
@ -539,8 +540,6 @@ update_widget_real (PpPPDOptionWidget *self)
default: default:
break; break;
} }
g_free (value);
} }
if (option->conflicted) if (option->conflicted)

View file

@ -202,10 +202,10 @@ markers_cmp (gconstpointer a,
} }
static gchar * 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 *breakpoint = NULL, *tmp2 = NULL;
gchar *printer_model = NULL; g_autofree gchar *tmp = NULL;
gchar backup; gchar backup;
size_t length = 0; size_t length = 0;
gchar *forbiden[] = { gchar *forbiden[] = {
@ -236,14 +236,12 @@ sanitize_printer_model (gchar *printer_make_and_model)
*breakpoint = backup; *breakpoint = backup;
if (length > 0) if (length > 0)
printer_model = g_strndup (printer_make_and_model, length); return g_strndup (printer_make_and_model, length);
} }
else else
printer_model = g_strdup (printer_make_and_model); return g_strdup (printer_make_and_model);
g_free (tmp); return NULL;
return printer_model;
} }
static gboolean static gboolean
@ -283,7 +281,7 @@ supply_levels_draw_cb (GtkWidget *widget,
{ {
GtkStyleContext *context; GtkStyleContext *context;
gboolean is_empty = TRUE; gboolean is_empty = TRUE;
gchar *tooltip_text = NULL; g_autofree gchar *tooltip_text = NULL;
gint width; gint width;
gint height; gint height;
int i; int i;
@ -303,7 +301,6 @@ supply_levels_draw_cb (GtkWidget *widget,
gchar **marker_colorsv = NULL; gchar **marker_colorsv = NULL;
gchar **marker_namesv = NULL; gchar **marker_namesv = NULL;
gchar **marker_typesv = NULL; gchar **marker_typesv = NULL;
gchar *tmp = NULL;
gtk_style_context_save (context); gtk_style_context_save (context);
@ -366,12 +363,10 @@ supply_levels_draw_cb (GtkWidget *widget,
if (tooltip_text) if (tooltip_text)
{ {
tmp = g_strdup_printf ("%s\n%s", g_autofree gchar *old_tooltip_text = g_steal_pointer (&tooltip_text);
tooltip_text, tooltip_text = g_strdup_printf ("%s\n%s",
old_tooltip_text,
((MarkerItem*) tmp_list->data)->name); ((MarkerItem*) tmp_list->data)->name);
g_free (tooltip_text);
tooltip_text = tmp;
tmp = NULL;
} }
else else
tooltip_text = g_strdup_printf ("%s", tooltip_text = g_strdup_printf ("%s",
@ -394,7 +389,6 @@ supply_levels_draw_cb (GtkWidget *widget,
if (tooltip_text) if (tooltip_text)
{ {
gtk_widget_set_tooltip_text (widget, tooltip_text); gtk_widget_set_tooltip_text (widget, tooltip_text);
g_free (tooltip_text);
} }
else else
{ {
@ -587,7 +581,7 @@ get_jobs_cb (GObject *source_object,
PpPrinter *printer = PP_PRINTER (source_object); PpPrinter *printer = PP_PRINTER (source_object);
g_autoptr(GError) error = NULL; g_autoptr(GError) error = NULL;
GList *jobs; GList *jobs;
gchar *button_label; g_autofree gchar *button_label = NULL;
gint num_jobs; gint num_jobs;
jobs = pp_printer_get_jobs_finish (printer, result, &error); 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); pp_jobs_dialog_update (self->pp_jobs_dialog);
} }
g_free (button_label);
g_clear_object (&self->get_jobs_cancellable); g_clear_object (&self->get_jobs_cancellable);
} }
@ -739,16 +731,15 @@ pp_printer_entry_new (cups_dest_t printer,
cups_ptype_t printer_type = 0; cups_ptype_t printer_type = 0;
gboolean is_accepting_jobs = TRUE; gboolean is_accepting_jobs = TRUE;
gboolean ink_supply_is_empty; gboolean ink_supply_is_empty;
gchar *instance; g_autofree gchar *instance = NULL;
gchar *printer_uri = NULL; const gchar *printer_uri = NULL;
gchar *location = NULL; const gchar *location = NULL;
gchar *printer_icon_name = NULL; g_autofree gchar *printer_icon_name = NULL;
gchar *default_icon_name = NULL; const gchar *printer_make_and_model = NULL;
gchar *printer_make_and_model = NULL; const gchar *reason = NULL;
gchar *reason = NULL;
gchar **printer_reasons = NULL; gchar **printer_reasons = NULL;
gchar *status = NULL; g_autofree gchar *status = NULL;
gchar *printer_status = NULL; g_autofree gchar *printer_status = NULL;
int i, j; int i, j;
static const char * const reasons[] = static const char * const reasons[] =
{ {
@ -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_image_set_from_icon_name (self->printer_icon, printer_icon_name, GTK_ICON_SIZE_DIALOG);
gtk_label_set_text (self->printer_status, printer_status); gtk_label_set_text (self->printer_status, printer_status);
g_free (printer_status);
gtk_label_set_text (self->printer_name_label, instance); gtk_label_set_text (self->printer_name_label, instance);
g_signal_handlers_block_by_func (self->printer_default_checkbutton, set_as_default_printer, self); 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); 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->printer_default_checkbutton), self->is_authorized);
gtk_widget_set_sensitive (GTK_WIDGET (self->remove_printer_menuitem), 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; return self;
} }

View file

@ -136,7 +136,7 @@ printer_rename_thread (GTask *task,
PpPrinter *self = PP_PRINTER (source_object); PpPrinter *self = PP_PRINTER (source_object);
gboolean result; gboolean result;
gchar *new_printer_name = task_data; gchar *new_printer_name = task_data;
gchar *old_printer_name; g_autofree gchar *old_printer_name = NULL;
g_object_get (self, "printer-name", &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_object_set (self, "printer-name", new_printer_name, NULL);
} }
g_free (old_printer_name);
g_task_return_boolean (task, result); g_task_return_boolean (task, result);
} }
@ -162,7 +160,6 @@ printer_rename_dbus_cb (GObject *source_object,
gboolean result = FALSE; gboolean result = FALSE;
g_autoptr(GError) error = NULL; g_autoptr(GError) error = NULL;
GTask *task = user_data; GTask *task = user_data;
gchar *old_printer_name;
output = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source_object), output = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source_object),
res, res,
@ -171,6 +168,7 @@ printer_rename_dbus_cb (GObject *source_object,
if (output != NULL) if (output != NULL)
{ {
g_autofree gchar *old_printer_name = NULL;
const gchar *ret_error; const gchar *ret_error;
self = g_task_get_source_object (task); 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_task_return_boolean (task, result);
g_free (old_printer_name);
g_variant_unref (output); g_variant_unref (output);
} }
else else
@ -217,11 +214,12 @@ get_bus_cb (GObject *source_object,
GDBusConnection *bus; GDBusConnection *bus;
g_autoptr(GError) error = NULL; g_autoptr(GError) error = NULL;
GTask *task = user_data; GTask *task = user_data;
gchar *printer_name;
bus = g_bus_get_finish (res, &error); bus = g_bus_get_finish (res, &error);
if (bus != NULL) if (bus != NULL)
{ {
g_autofree gchar *printer_name = NULL;
g_object_get (g_task_get_source_object (task), g_object_get (g_task_get_source_object (task),
"printer-name", &printer_name, "printer-name", &printer_name,
NULL); NULL);
@ -239,8 +237,6 @@ get_bus_cb (GObject *source_object,
g_task_get_cancellable (task), g_task_get_cancellable (task),
printer_rename_dbus_cb, printer_rename_dbus_cb,
task); task);
g_free (printer_name);
} }
else else
{ {
@ -306,7 +302,7 @@ get_jobs_thread (GTask *task,
gchar *job_uri; gchar *job_uri;
gchar *printer_uri; gchar *printer_uri;
gchar **auth_info_required = NULL; gchar **auth_info_required = NULL;
gchar *printer_name; g_autofree gchar *printer_name = NULL;
GList *list = NULL; GList *list = NULL;
gint num_jobs; gint num_jobs;
gint i, j; gint i, j;
@ -323,7 +319,7 @@ get_jobs_thread (GTask *task,
auth_info_is_required = FALSE; auth_info_is_required = FALSE;
if (jobs[i].state == IPP_JOB_HELD) 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); job_request = ippNewRequest (IPP_GET_JOB_ATTRIBUTES);
ippAddString (job_request, IPP_TAG_OPERATION, IPP_TAG_URI, ippAddString (job_request, IPP_TAG_OPERATION, IPP_TAG_URI,
@ -334,8 +330,6 @@ get_jobs_thread (GTask *task,
"requested-attributes", NULL, "job-hold-until"); "requested-attributes", NULL, "job-hold-until");
job_response = cupsDoRequest (CUPS_HTTP_DEFAULT, job_request, "/"); job_response = cupsDoRequest (CUPS_HTTP_DEFAULT, job_request, "/");
g_free (job_uri);
if (job_response != NULL) if (job_response != NULL)
{ {
attr = ippFindAttribute (job_response, "job-hold-until", IPP_TAG_ZERO); attr = ippFindAttribute (job_response, "job-hold-until", IPP_TAG_ZERO);
@ -345,7 +339,7 @@ get_jobs_thread (GTask *task,
if (auth_info_required == NULL) 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); printer_request = ippNewRequest (IPP_GET_PRINTER_ATTRIBUTES);
ippAddString (printer_request, IPP_TAG_OPERATION, IPP_TAG_URI, 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); "requested-attributes", 1, NULL, (const char **) printer_attributes);
printer_response = cupsDoRequest (CUPS_HTTP_DEFAULT, printer_request, "/"); printer_response = cupsDoRequest (CUPS_HTTP_DEFAULT, printer_request, "/");
g_free (printer_uri);
if (printer_response != NULL) if (printer_response != NULL)
{ {
attr = ippFindAttribute (printer_response, "auth-info-required", IPP_TAG_ZERO); attr = ippFindAttribute (printer_response, "auth-info-required", IPP_TAG_ZERO);
@ -389,7 +381,6 @@ get_jobs_thread (GTask *task,
g_strfreev (auth_info_required); g_strfreev (auth_info_required);
cupsFreeJobs (num_jobs, jobs); cupsFreeJobs (num_jobs, jobs);
g_free (printer_name);
if (g_task_set_return_on_cancel (task, FALSE)) if (g_task_set_return_on_cancel (task, FALSE))
{ {
@ -438,7 +429,6 @@ pp_printer_delete_dbus_cb (GObject *source_object,
gboolean result = FALSE; gboolean result = FALSE;
g_autoptr(GError) error = NULL; g_autoptr(GError) error = NULL;
GTask *task = user_data; GTask *task = user_data;
gchar *printer_name;
output = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source_object), output = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source_object),
res, res,
@ -447,6 +437,7 @@ pp_printer_delete_dbus_cb (GObject *source_object,
if (output != NULL) if (output != NULL)
{ {
g_autofree gchar *printer_name = NULL;
const gchar *ret_error; const gchar *ret_error;
g_object_get (g_task_get_source_object (task), "printer-name", &printer_name, NULL); 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_task_return_boolean (task, result);
g_free (printer_name);
g_variant_unref (output); g_variant_unref (output);
} }
else else
@ -478,11 +468,12 @@ pp_printer_delete_cb (GObject *source_object,
GDBusConnection *bus; GDBusConnection *bus;
g_autoptr(GError) error = NULL; g_autoptr(GError) error = NULL;
GTask *task = user_data; GTask *task = user_data;
gchar *printer_name;
bus = g_bus_get_finish (res, &error); bus = g_bus_get_finish (res, &error);
if (bus != NULL) if (bus != NULL)
{ {
g_autofree gchar *printer_name = NULL;
g_object_get (g_task_get_source_object (task), g_object_get (g_task_get_source_object (task),
"printer-name", &printer_name, "printer-name", &printer_name,
NULL); NULL);
@ -499,8 +490,6 @@ pp_printer_delete_cb (GObject *source_object,
g_task_get_cancellable (task), g_task_get_cancellable (task),
pp_printer_delete_dbus_cb, pp_printer_delete_dbus_cb,
task); task);
g_free (printer_name);
} }
else else
{ {
@ -562,9 +551,9 @@ print_file_thread (GTask *task,
cups_dest_t *dest = NULL; cups_dest_t *dest = NULL;
const gchar *printer_type = NULL; const gchar *printer_type = NULL;
gboolean ret = FALSE; gboolean ret = FALSE;
gchar *printer_name = NULL; g_autofree gchar *printer_name = NULL;
gchar *printer_uri = NULL; g_autofree gchar *printer_uri = NULL;
gchar *resource = NULL; g_autofree gchar *resource = NULL;
ipp_t *response = NULL; ipp_t *response = NULL;
ipp_t *request; ipp_t *request;
@ -613,10 +602,6 @@ print_file_thread (GTask *task,
ippDelete (response); ippDelete (response);
} }
g_free (printer_name);
g_free (printer_uri);
g_free (resource);
if (g_task_set_return_on_cancel (task, FALSE)) if (g_task_set_return_on_cancel (task, FALSE))
{ {
g_task_return_boolean (task, ret); g_task_return_boolean (task, ret);

View file

@ -282,11 +282,8 @@ list_dir (SMBCCTX *smb_context,
while (dir && (dirent = smbclient_readdir (smb_context, dir))) while (dir && (dirent = smbclient_readdir (smb_context, dir)))
{ {
gchar *device_name; g_autofree gchar *subdirname = NULL;
gchar *device_uri; g_autofree gchar *subpath = NULL;
gchar *subdirname = NULL;
gchar *subpath = NULL;
gchar *uri;
if (dirent->smbc_type == SMBC_WORKGROUP) if (dirent->smbc_type == SMBC_WORKGROUP)
{ {
@ -302,6 +299,10 @@ list_dir (SMBCCTX *smb_context,
if (dirent->smbc_type == SMBC_PRINTER_SHARE) 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); uri = g_strdup_printf ("%s/%s", dirname, dirent->name);
device_uri = g_uri_escape_string (uri, device_uri = g_uri_escape_string (uri,
G_URI_RESERVED_CHARS_GENERIC_DELIMITERS G_URI_RESERVED_CHARS_GENERIC_DELIMITERS
@ -309,7 +310,7 @@ list_dir (SMBCCTX *smb_context,
FALSE); FALSE);
device_name = g_strdup (dirent->name); 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 = g_object_new (PP_TYPE_PRINT_DEVICE,
"device-uri", device_uri, "device-uri", device_uri,
@ -321,10 +322,6 @@ list_dir (SMBCCTX *smb_context,
"host-name", dirname, "host-name", dirname,
NULL); NULL);
g_free (device_name);
g_free (device_uri);
g_free (uri);
data->devices->devices = g_list_append (data->devices->devices, device); data->devices->devices = g_list_append (data->devices->devices, device);
} }
@ -335,8 +332,6 @@ list_dir (SMBCCTX *smb_context,
subpath, subpath,
cancellable, cancellable,
data); data);
g_free (subdirname);
g_free (subpath);
} }
} }

View file

@ -111,17 +111,15 @@ get_tag_value (const gchar *tag_string, const gchar *tag_name)
static gchar * static gchar *
normalize (const gchar *input_string) normalize (const gchar *input_string)
{ {
gchar *tmp = NULL;
gchar *res = NULL;
gchar *result = NULL; gchar *result = NULL;
gint i, j = 0, k = -1; gint i, j = 0, k = -1;
if (input_string) 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) 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++) for (i = 0; i < strlen (tmp); i++)
{ {
@ -154,8 +152,6 @@ normalize (const gchar *input_string)
res[j] = '\0'; res[j] = '\0';
result = g_strdup (res); 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_dest_t *dest = NULL;
cups_job_t *jobs = NULL; cups_job_t *jobs = NULL;
GDBusConnection *bus; GDBusConnection *bus;
const char *printer_location = NULL; const gchar *printer_location = NULL;
const char *printer_info = NULL; const gchar *printer_info = NULL;
const char *printer_uri = NULL; const gchar *printer_uri = NULL;
const char *device_uri = NULL; const gchar *device_uri = NULL;
const char *job_sheets = NULL; const gchar *job_sheets = NULL;
gboolean result = FALSE; gboolean result = FALSE;
gboolean accepting = TRUE; gboolean accepting = TRUE;
gboolean printer_paused = FALSE; gboolean printer_paused = FALSE;
@ -275,16 +271,16 @@ printer_rename (const gchar *old_name,
gboolean printer_shared = FALSE; gboolean printer_shared = FALSE;
g_autoptr(GError) error = NULL; g_autoptr(GError) error = NULL;
http_t *http; http_t *http;
gchar *ppd_link; g_autofree gchar *ppd_link = NULL;
gchar *ppd_filename = NULL; g_autofree gchar *ppd_filename = NULL;
gchar **sheets = NULL; gchar **sheets = NULL;
gchar **users_allowed = NULL; gchar **users_allowed = NULL;
gchar **users_denied = NULL; gchar **users_denied = NULL;
gchar **member_names = NULL; gchar **member_names = NULL;
gchar *start_sheet = NULL; const gchar *start_sheet = NULL;
gchar *end_sheet = NULL; const gchar *end_sheet = NULL;
gchar *error_policy = NULL; g_autofree gchar *error_policy = NULL;
gchar *op_policy = NULL; g_autofree gchar *op_policy = NULL;
ipp_t *request; ipp_t *request;
ipp_t *response; ipp_t *response;
gint i; gint i;
@ -498,8 +494,6 @@ printer_rename (const gchar *old_name,
if (ppd_link) if (ppd_link)
{ {
g_unlink (ppd_link); g_unlink (ppd_link);
g_free (ppd_link);
g_free (ppd_filename);
} }
num_dests = cupsGetDests (&dests); num_dests = cupsGetDests (&dests);
@ -525,8 +519,6 @@ printer_rename (const gchar *old_name,
printer_set_accepting_jobs (old_name, accepting, NULL); printer_set_accepting_jobs (old_name, accepting, NULL);
cupsFreeDests (num_dests, dests); cupsFreeDests (num_dests, dests);
g_free (op_policy);
g_free (error_policy);
if (sheets) if (sheets)
g_strfreev (sheets); g_strfreev (sheets);
if (users_allowed) if (users_allowed)
@ -1285,7 +1277,7 @@ get_ipp_attributes_func (gpointer user_data)
GIAData *data = (GIAData *) user_data; GIAData *data = (GIAData *) user_data;
ipp_t *request; ipp_t *request;
ipp_t *response = NULL; ipp_t *response = NULL;
gchar *printer_uri; g_autofree gchar *printer_uri = NULL;
char **requested_attrs = NULL; char **requested_attrs = NULL;
gint i, j, length = 0; 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[i]);
g_free (requested_attrs); g_free (requested_attrs);
g_free (printer_uri);
get_ipp_attributes_cb (data); get_ipp_attributes_cb (data);
return NULL; return NULL;
@ -1764,13 +1754,12 @@ get_ppds_attribute_func (gpointer user_data)
ppd_file_t *ppd_file; ppd_file_t *ppd_file;
ppd_attr_t *ppd_attr; ppd_attr_t *ppd_attr;
GPAData *data = (GPAData *) user_data; GPAData *data = (GPAData *) user_data;
gchar *ppd_filename;
gint i; gint i;
data->result = g_new0 (gchar *, g_strv_length (data->ppds_names) + 1); data->result = g_new0 (gchar *, g_strv_length (data->ppds_names) + 1);
for (i = 0; data->ppds_names[i]; i++) 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) if (ppd_filename)
{ {
ppd_file = ppdOpenFile (ppd_filename); ppd_file = ppdOpenFile (ppd_filename);
@ -1784,7 +1773,6 @@ get_ppds_attribute_func (gpointer user_data)
} }
g_unlink (ppd_filename); g_unlink (ppd_filename);
g_free (ppd_filename);
} }
} }
@ -1943,8 +1931,6 @@ get_ppd_names_async_dbus_scb (GObject *source_object,
{ {
GVariantIter *iter; GVariantIter *iter;
GVariant *item; GVariant *item;
gchar *driver;
gchar *match;
for (j = 0; j < G_N_ELEMENTS (match_levels) && n < data->count; j++) 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))) while ((item = g_variant_iter_next_value (iter)))
{ {
const gchar *driver, *match;
g_variant_get (item, g_variant_get (item,
"(ss)", "(&s&s)",
&driver, &driver,
&match); &match);
@ -1980,8 +1968,6 @@ get_ppd_names_async_dbus_scb (GObject *source_object,
n++; n++;
} }
g_free (driver);
g_free (match);
g_variant_unref (item); g_variant_unref (item);
} }
} }
@ -2186,11 +2172,7 @@ get_device_attributes_async_dbus_cb (GObject *source_object,
if (data->device_uri) if (data->device_uri)
{ {
gchar *key; g_autofree gchar *suffix = NULL;
gchar *value;
gchar *number;
gchar *endptr;
gchar *suffix;
g_variant_get (devices_variant, g_variant_get (devices_variant,
"a{ss}", "a{ss}",
@ -2198,16 +2180,20 @@ get_device_attributes_async_dbus_cb (GObject *source_object,
while ((item = g_variant_iter_next_value (iter))) while ((item = g_variant_iter_next_value (iter)))
{ {
const gchar *key, *value;
g_variant_get (item, g_variant_get (item,
"{ss}", "{&s&s}",
&key, &key,
&value); &value);
if (g_str_equal (value, data->device_uri)) if (g_str_equal (value, data->device_uri))
{ {
number = g_strrstr (key, ":"); gchar *number = g_strrstr (key, ":");
if (number != NULL) if (number != NULL)
{ {
gchar *endptr;
number++; number++;
index = g_ascii_strtoll (number, &endptr, 10); index = g_ascii_strtoll (number, &endptr, 10);
if (index == 0 && endptr == (number)) 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); 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))) while ((item = g_variant_iter_next_value (iter)))
{ {
gchar *key; const gchar *key, *value;
gchar *value;
g_variant_get (item, g_variant_get (item,
"{ss}", "{&s&s}",
&key, &key,
&value); &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_variant_unref (item);
} }
g_free (suffix);
} }
g_variant_unref (devices_variant); g_variant_unref (devices_variant);
@ -2631,14 +2610,6 @@ get_all_ppds_func (gpointer user_data)
ipp_t *request; ipp_t *request;
ipp_t *response; ipp_t *response;
GList *list; 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; gchar *manufacturer_display_name;
gint i, j; gint i, j;
@ -2671,21 +2642,21 @@ get_all_ppds_func (gpointer user_data)
for (attr = ippFirstAttribute (response); attr != NULL; attr = ippNextAttribute (response)) 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) while (attr != NULL && ippGetGroupTag (attr) != IPP_TAG_PRINTER)
attr = ippNextAttribute (response); attr = ippNextAttribute (response);
if (attr == NULL) if (attr == NULL)
break; 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) while (attr != NULL && ippGetGroupTag (attr) == IPP_TAG_PRINTER)
{ {
if (g_strcmp0 (ippGetName (attr), "ppd-device-id") == 0 && 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) if (attr == NULL)
break; break;
} }
@ -2961,27 +2928,23 @@ ppd_list_free (PPDList *list)
gchar * gchar *
get_standard_manufacturers_name (const gchar *name) get_standard_manufacturers_name (const gchar *name)
{ {
gchar *normalized_name; g_autofree gchar *normalized_name = NULL;
gchar *result = NULL;
gint i; gint i;
if (name) if (name == NULL)
{ return NULL;
normalized_name = normalize (name); normalized_name = normalize (name);
for (i = 0; i < G_N_ELEMENTS (manufacturers_names); i++) 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); return g_strdup (manufacturers_names[i].display_name);
break;
} }
} }
g_free (normalized_name); return NULL;
}
return result;
} }
typedef struct typedef struct
@ -3307,7 +3270,7 @@ typedef struct
} GCDData; } GCDData;
static gint static gint
get_suffix_index (gchar *string) get_suffix_index (const gchar *string)
{ {
gchar *number; gchar *number;
gchar *endptr; gchar *endptr;
@ -3361,21 +3324,19 @@ get_cups_devices_async_dbus_cb (GObject *source_object,
{ {
GVariantIter *iter; GVariantIter *iter;
GVariant *item; GVariant *item;
gchar *key;
gchar *value;
gint index = -1, max_index = -1, i; gint index = -1, max_index = -1, i;
g_variant_get (devices_variant, "a{ss}", &iter); g_variant_get (devices_variant, "a{ss}", &iter);
while ((item = g_variant_iter_next_value (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); index = get_suffix_index (key);
if (index > max_index) if (index > max_index)
max_index = index; max_index = index;
g_free (key);
g_free (value);
g_variant_unref (item); 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); g_variant_get (devices_variant, "a{ss}", &iter);
while ((item = g_variant_iter_next_value (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); index = get_suffix_index (key);
if (index >= 0) 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_object_set (devices[index], "acquisition-method", ACQUISITION_METHOD_DEFAULT_CUPS_SERVER, NULL);
} }
g_free (key);
g_free (value);
g_variant_unref (item); g_variant_unref (item);
} }
@ -3461,7 +3422,7 @@ get_cups_devices_async_dbus_cb (GObject *source_object,
{ {
GVariantBuilder *include_scheme_builder = NULL; GVariantBuilder *include_scheme_builder = NULL;
GVariantBuilder *exclude_scheme_builder = NULL; GVariantBuilder *exclude_scheme_builder = NULL;
gchar *backend_name; g_autofree gchar *backend_name = NULL;
backend_name = data->backend_list->data; 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 (); exclude_scheme_builder = create_other_backends_array ();
} }
g_free (backend_name);
data->backend_list = g_list_remove_link (data->backend_list, data->backend_list); 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)), 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; GVariantBuilder include_scheme_builder;
GCDData *data; GCDData *data;
g_autoptr(GError) error = NULL; 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); bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
if (!bus) 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_init (&include_scheme_builder, G_VARIANT_TYPE ("as"));
g_variant_builder_add (&include_scheme_builder, "s", backend_name); 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); data->backend_list = g_list_remove_link (data->backend_list, data->backend_list);
g_dbus_connection_call (bus, g_dbus_connection_call (bus,
@ -3665,9 +3624,7 @@ canonicalize_device_name (GList *device_names,
gboolean already_present; gboolean already_present;
GList *iter; GList *iter;
gsize len; gsize len;
gchar *name = NULL; g_autofree gchar *name = NULL;
gchar *new_name;
gchar *lower_name;
gchar *occurrence; gchar *occurrence;
gint name_index, j; gint name_index, j;
static const char * const residues[] = { static const char * const residues[] = {
@ -3725,7 +3682,7 @@ canonicalize_device_name (GList *device_names,
/* Remove common strings found in driver names */ /* Remove common strings found in driver names */
for (j = 0; j < G_N_ELEMENTS (residues); j++) 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]); occurrence = g_strrstr (lower_name, residues[j]);
if (occurrence != NULL) if (occurrence != NULL)
@ -3733,8 +3690,6 @@ canonicalize_device_name (GList *device_names,
occurrence[0] = '\0'; occurrence[0] = '\0';
name[strlen (lower_name)] = '\0'; name[strlen (lower_name)] = '\0';
} }
g_free (lower_name);
} }
/* Remove trailing "-" */ /* Remove trailing "-" */
@ -3756,8 +3711,10 @@ canonicalize_device_name (GList *device_names,
name_index = 2; name_index = 2;
already_present = FALSE; already_present = FALSE;
do while (TRUE)
{ {
g_autofree gchar *new_name = NULL;
if (already_present) if (already_present)
{ {
new_name = g_strdup_printf ("%s-%d", name, name_index); new_name = g_strdup_printf ("%s-%d", name, name_index);
@ -3787,14 +3744,9 @@ canonicalize_device_name (GList *device_names,
already_present = TRUE; already_present = TRUE;
} }
if (already_present) if (!already_present)
g_free (new_name); return g_steal_pointer (&new_name);
}
} while (already_present);
g_free (name);
return new_name;
} }
void void