summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorChristophe Fergeau <cfergeau@redhat.com>2012-11-22 19:04:48 +0100
committerChristophe Fergeau <cfergeau@redhat.com>2012-11-26 10:19:31 +0100
commite8659679cd3f8a7f02446cccf8def92231f9fd09 (patch)
tree4c0c17e8a85064a023fdc595e3504ece71436b5e /modules
parent693581250e86895fdb3c296ced800ba6ef4ce459 (diff)
downloadgtk+-e8659679cd3f8a7f02446cccf8def92231f9fd09.tar.gz
Sanitize memory handling in cups_request_printer_list_cb
gtk+ was trying to display already freed strings, leaking memory, ...I noticed this because I was getting weird blinking characters as the status of my cups printers, and valgrind confirmed something was wrong. https://bugzilla.gnome.org/show_bug.cgi?id=683072
Diffstat (limited to 'modules')
-rw-r--r--modules/printbackends/cups/gtkprintbackendcups.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/modules/printbackends/cups/gtkprintbackendcups.c b/modules/printbackends/cups/gtkprintbackendcups.c
index 3c28a849fd..2c4bee9f4a 100644
--- a/modules/printbackends/cups/gtkprintbackendcups.c
+++ b/modules/printbackends/cups/gtkprintbackendcups.c
@@ -1696,7 +1696,7 @@ typedef struct
const gchar *member_uris;
const gchar *location;
const gchar *description;
- const gchar *state_msg;
+ gchar *state_msg;
const gchar *reason_msg;
PrinterStateLevel reason_level;
gint state;
@@ -1732,7 +1732,7 @@ cups_printer_handle_attribute (GtkPrintBackendCups *cups_backend,
else if (strcmp (ippGetName (attr), "printer-info") == 0)
info->description = ippGetString (attr, 0, NULL);
else if (strcmp (ippGetName (attr), "printer-state-message") == 0)
- info->state_msg = ippGetString (attr, 0, NULL);
+ info->state_msg = g_strdup (ippGetString (attr, 0, NULL));
else if (strcmp (ippGetName (attr), "printer-state-reasons") == 0)
/* Store most important reason to reason_msg and set
its importance at printer_state_reason_level */
@@ -2130,8 +2130,8 @@ cups_request_printer_list_cb (GtkPrintBackendCups *cups_backend,
if (tmp_msg2 != NULL)
{
+ g_free (info->state_msg);
info->state_msg = tmp_msg2;
- g_free (tmp_msg2);
}
}
@@ -2159,14 +2159,18 @@ cups_request_printer_list_cb (GtkPrintBackendCups *cups_backend,
if (info->reason_level >= GTK_PRINTER_STATE_LEVEL_WARNING)
{
if (strlen (info->state_msg) == 0)
- info->state_msg = reason_msg_desc;
+ {
+ g_free (info->state_msg);
+ info->state_msg = reason_msg_desc;
+ reason_msg_desc = NULL;
+ }
else
{
gchar *tmp_msg = NULL;
tmp_msg = g_strjoin (" ; ", info->state_msg,
reason_msg_desc, NULL);
+ g_free (info->state_msg);
info->state_msg = tmp_msg;
- g_free (tmp_msg);
}
}
if (reason_msg_desc != NULL)
@@ -2195,6 +2199,7 @@ cups_request_printer_list_cb (GtkPrintBackendCups *cups_backend,
/* The ref is held by GtkPrintBackend, in add_printer() */
g_object_unref (printer);
+ g_free (info->state_msg);
g_slice_free (PrinterSetupInfo, info);
if (attr == NULL)