summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Withnall <philip.withnall@collabora.co.uk>2013-11-26 15:04:45 +0000
committerPhilip Withnall <philip.withnall@collabora.co.uk>2015-03-09 13:41:37 +0000
commitaf36220bca74837cefab046a6435f2b6743c4569 (patch)
treec9a3f625d6370ebd9b53699787e8a59951ced3e1
parent8e3b49969905182c903dc62f0f6e6debefefe973 (diff)
downloadgtk+-af36220bca74837cefab046a6435f2b6743c4569.tar.gz
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
-rw-r--r--gtk/gtkprintcontext.c5
-rw-r--r--gtk/gtkprintunixdialog.c8
2 files changed, 7 insertions, 6 deletions
diff --git a/gtk/gtkprintcontext.c b/gtk/gtkprintcontext.c
index f65de539cc..d3c5a02635 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 e1c19bc6e9..85fca0d332 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;