From a788ef97a4d51334de280075ed1dedcbc2d74e0f Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Mon, 30 Apr 2007 04:45:33 +0000 Subject: [PATCH] Fix some issues with reference handling in the printing code. (#429902, 2007-04-29 Matthias Clasen Fix some issues with reference handling in the printing code. (#429902, Mathias Hasselmann) * gtk/gtkprintoperation.c (gtk_print_operation_finalize): Unref the print context, if we have one. (gtk_print_operation_done): Add a default ::done handler that unrefs the print context. (preview_ready): Take a reference on the print operation preview here. (print_pages_idle): ...not here, (preview_print_idle_done): ...and release it here. * tests/print-editor.c (preview_cb): Take a reference on the print operation here. svn path=/trunk/; revision=17722 --- ChangeLog | 17 +++++++++++++++++ gtk/gtkprintoperation.c | 23 ++++++++++++++++++++--- tests/print-editor.c | 2 +- 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7178af325c..a20d462462 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,20 @@ +2007-04-29 Matthias Clasen + + Fix some issues with reference handling in the printing + code. (#429902, Mathias Hasselmann) + + * gtk/gtkprintoperation.c (gtk_print_operation_finalize): + Unref the print context, if we have one. + (gtk_print_operation_done): Add a default ::done handler + that unrefs the print context. + (preview_ready): Take a reference on the print operation + preview here. + (print_pages_idle): ...not here, + (preview_print_idle_done): ...and release it here. + + * tests/print-editor.c (preview_cb): Take a reference + on the print operation here. + 2007-04-29 Matthias Clasen * gtk/gtkprintoperation.c (print_pages_idle): Don't get diff --git a/gtk/gtkprintoperation.c b/gtk/gtkprintoperation.c index ed038152c7..fe92a5cf6d 100644 --- a/gtk/gtkprintoperation.c +++ b/gtk/gtkprintoperation.c @@ -120,6 +120,9 @@ gtk_print_operation_finalize (GObject *object) if (priv->print_settings) g_object_unref (priv->print_settings); + if (priv->print_context) + g_object_unref (priv->print_context); + g_free (priv->export_filename); g_free (priv->job_name); g_free (priv->custom_tab_label); @@ -396,6 +399,8 @@ preview_print_idle_done (gpointer data) g_free (pop->filename); gtk_print_operation_preview_end_preview (pop->preview); + + g_object_unref (op); g_free (pop); } @@ -447,6 +452,8 @@ preview_ready (GtkPrintOperationPreview *preview, pop->page_nr = 0; pop->print_context = context; + g_object_ref (preview); + gdk_threads_add_idle_full (G_PRIORITY_DEFAULT_IDLE + 10, preview_print_idle, pop, @@ -495,6 +502,18 @@ gtk_print_operation_create_custom_widget (GtkPrintOperation *operation) return NULL; } +static void +gtk_print_operation_done (GtkPrintOperation *operation) +{ + GtkPrintOperationPrivate *priv = operation->priv; + + if (priv->print_context) + { + g_object_unref (priv->print_context); + priv->print_context = NULL; + } +} + static gboolean custom_widget_accumulator (GSignalInvocationHint *ihint, GValue *return_accu, @@ -523,6 +542,7 @@ gtk_print_operation_class_init (GtkPrintOperationClass *class) class->preview = gtk_print_operation_preview_handler; class->create_custom_widget = gtk_print_operation_create_custom_widget; + class->done = gtk_print_operation_done; g_type_class_add_private (gobject_class, sizeof (GtkPrintOperationPrivate)); @@ -1935,7 +1955,6 @@ print_pages_idle_done (gpointer user_data) GTK_PRINT_OPERATION_RESULT_APPLY); g_object_unref (data->op); - g_free (data); } @@ -2129,8 +2148,6 @@ print_pages_idle (gpointer user_data) { done = TRUE; - g_object_ref (data->op); - g_signal_emit_by_name (data->op, "ready", priv->print_context); goto out; } diff --git a/tests/print-editor.c b/tests/print-editor.c index 8e11e4bbb7..9b47ce8d55 100644 --- a/tests/print-editor.c +++ b/tests/print-editor.c @@ -578,7 +578,7 @@ preview_cb (GtkPrintOperation *op, gtk_print_context_set_cairo_context (context, cr, 72, 72); cairo_destroy (cr); - pop->op = op; + pop->op = g_object_ref (op); pop->preview = preview; pop->spin = page; pop->area = da;