[gtk/4627-printing-Unref-old-spool_io-before-setting-new-one] printing: Unref old spool_io before setting new one



commit 915090f1182a2981768c8d1de6ffbeea54d3dfbc
Author: Marek Kasik <mkasik redhat com>
Date:   Wed Jan 12 12:36:44 2022 +0100

    printing: Unref old spool_io before setting new one
    
    Unref private spool_io of GtkPrintJob before setting it to a new one
    in gtk_print_job_set_source_file() and gtk_print_job_set_source_fd()
    to prevent a leak.
    
    Fixes: #4627

 gtk/gtkprintjob.c | 6 ++++++
 1 file changed, 6 insertions(+)
---
diff --git a/gtk/gtkprintjob.c b/gtk/gtkprintjob.c
index 945a43a0d9..d04c506a7e 100644
--- a/gtk/gtkprintjob.c
+++ b/gtk/gtkprintjob.c
@@ -441,6 +441,9 @@ gtk_print_job_set_source_file (GtkPrintJob *job,
 
   g_return_val_if_fail (GTK_IS_PRINT_JOB (job), FALSE);
 
+  if (job->spool_io != NULL)
+    g_io_channel_unref (job->spool_io);
+
   job->spool_io = g_io_channel_new_file (filename, "r", &tmp_error);
 
   if (tmp_error == NULL)
@@ -483,6 +486,9 @@ gtk_print_job_set_source_fd (GtkPrintJob  *job,
   g_return_val_if_fail (GTK_IS_PRINT_JOB (job), FALSE);
   g_return_val_if_fail (fd >= 0, FALSE);
 
+  if (job->spool_io != NULL)
+    g_io_channel_unref (job->spool_io);
+
   job->spool_io = g_io_channel_unix_new (fd);
   if (g_io_channel_set_encoding (job->spool_io, NULL, error) != G_IO_STATUS_NORMAL)
     return FALSE;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]