[gtk+] gtkprintcontext: Fix several potential g_object_[un]ref(NULL) calls



commit af36220bca74837cefab046a6435f2b6743c4569
Author: Philip Withnall <philip withnall collabora co uk>
Date:   Tue Nov 26 15:04:45 2013 +0000

    gtkprintcontext: Fix several potential g_object_[un]ref(NULL) calls
    
    The page_setup of a GtkPrintContext or GtkPrintUnixDialog is nullable,
    so all reference count changes to it have to be guarded against NULL
    values.
    
    Found by scan-build.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=712760

 gtk/gtkprintcontext.c    |    5 +++--
 gtk/gtkprintunixdialog.c |    8 ++++----
 2 files changed, 7 insertions(+), 6 deletions(-)
---
diff --git a/gtk/gtkprintcontext.c b/gtk/gtkprintcontext.c
index f65de53..d3c5a02 100644
--- a/gtk/gtkprintcontext.c
+++ b/gtk/gtkprintcontext.c
@@ -355,8 +355,9 @@ _gtk_print_context_set_page_setup (GtkPrintContext *context,
   g_return_if_fail (GTK_IS_PRINT_CONTEXT (context));
   g_return_if_fail (page_setup == NULL ||
                    GTK_IS_PAGE_SETUP (page_setup));
-  
-  g_object_ref (page_setup);
+
+  if (page_setup != NULL)
+    g_object_ref (page_setup);
 
   if (context->page_setup != NULL)
     g_object_unref (context->page_setup);
diff --git a/gtk/gtkprintunixdialog.c b/gtk/gtkprintunixdialog.c
index e1c19bc..85fca0d 100644
--- a/gtk/gtkprintunixdialog.c
+++ b/gtk/gtkprintunixdialog.c
@@ -2092,8 +2092,8 @@ selected_printer_changed (GtkTreeSelection   *selection,
           if (page_setup && priv->page_setup)
             gtk_page_setup_set_orientation (page_setup, gtk_page_setup_get_orientation (priv->page_setup));
 
-          g_object_unref (priv->page_setup);
-          priv->page_setup = page_setup;
+          g_clear_object (&priv->page_setup);
+          priv->page_setup = page_setup; /* transfer ownership */
         }
 
       priv->printer_capabilities = gtk_printer_get_capabilities (printer);
@@ -3249,7 +3249,7 @@ custom_paper_dialog_response_cb (GtkDialog *custom_paper_dialog,
                              gtk_paper_size_get_display_name (gtk_page_setup_get_paper_size 
(priv->page_setup))) == 0)
                 gtk_print_unix_dialog_set_page_setup (print_dialog, page_setup);
 
-              g_object_unref (page_setup);
+              g_clear_object (&page_setup);
             } while (gtk_tree_model_iter_next (model, &iter));
         }
     }
@@ -3437,7 +3437,7 @@ gtk_print_unix_dialog_set_page_setup (GtkPrintUnixDialog *dialog,
 
   if (priv->page_setup != page_setup)
     {
-      g_object_unref (priv->page_setup);
+      g_clear_object (&priv->page_setup);
       priv->page_setup = g_object_ref (page_setup);
 
       priv->page_setup_set = TRUE;


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