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
This commit is contained in:
Philip Withnall 2013-11-26 15:04:45 +00:00
parent 8e3b499699
commit af36220bca
2 changed files with 7 additions and 6 deletions

View File

@ -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);

View File

@ -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;