[gtk/window-destroy: 6/16] fontchooserdialog: Fix disposing



commit b6354c53916c6e60d380aa400fd6ea5c02a843ca
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat May 9 14:10:38 2020 -0400

    fontchooserdialog: Fix disposing
    
    We need to drop our widgetry in dispose to prevent
    leakage.

 gtk/gtkfontchooserdialog.c | 52 +++++++++++++++++++++++++++++++++-------------
 1 file changed, 37 insertions(+), 15 deletions(-)
---
diff --git a/gtk/gtkfontchooserdialog.c b/gtk/gtkfontchooserdialog.c
index 11d17c9668..9083806f89 100644
--- a/gtk/gtkfontchooserdialog.c
+++ b/gtk/gtkfontchooserdialog.c
@@ -48,7 +48,6 @@ struct _GtkFontChooserDialog
   GtkDialog parent_instance;
 
   GtkWidget *fontchooser;
-
   GtkWidget *select_button;
   GtkWidget *cancel_button;
   GtkWidget *tweak_button;
@@ -200,12 +199,49 @@ gtk_font_chooser_dialog_map (GtkWidget *widget)
   GTK_WIDGET_CLASS (gtk_font_chooser_dialog_parent_class)->map (widget);
 }
 
+static void
+update_button (GtkFontChooserDialog *dialog)
+{
+  PangoFontDescription *desc;
+
+  desc = gtk_font_chooser_get_font_desc (GTK_FONT_CHOOSER (dialog->fontchooser));
+
+  gtk_widget_set_sensitive (dialog->select_button, desc != NULL);
+
+  if (desc)
+    pango_font_description_free (desc);
+}
+
+static void
+gtk_font_chooser_dialog_dispose (GObject *object)
+{
+  GtkFontChooserDialog *dialog = GTK_FONT_CHOOSER_DIALOG (object);
+
+  if (dialog->fontchooser)
+    {
+      g_signal_handlers_disconnect_by_func (dialog->fontchooser,
+                                            update_button,
+                                            dialog);
+      g_signal_handlers_disconnect_by_func (dialog->fontchooser,
+                                            update_tweak_button,
+                                            dialog);
+    }
+
+  g_clear_pointer (&dialog->select_button, gtk_widget_unparent);
+  g_clear_pointer (&dialog->cancel_button, gtk_widget_unparent);
+  g_clear_pointer (&dialog->tweak_button, gtk_widget_unparent);
+  g_clear_pointer (&dialog->fontchooser, gtk_widget_unparent);
+
+  G_OBJECT_CLASS (gtk_font_chooser_dialog_parent_class)->dispose (object);
+}
+
 static void
 gtk_font_chooser_dialog_class_init (GtkFontChooserDialogClass *klass)
 {
   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
 
+  gobject_class->dispose = gtk_font_chooser_dialog_dispose;
   gobject_class->get_property = gtk_font_chooser_dialog_get_property;
   gobject_class->set_property = gtk_font_chooser_dialog_set_property;
 
@@ -225,20 +261,6 @@ gtk_font_chooser_dialog_class_init (GtkFontChooserDialogClass *klass)
   gtk_widget_class_bind_template_callback (widget_class, dialog_forward_key);
 }
 
-static void
-update_button (GtkFontChooserDialog *dialog)
-{
-  PangoFontDescription *desc;
-
-  desc = gtk_font_chooser_get_font_desc (GTK_FONT_CHOOSER (dialog->fontchooser));
-
-  gtk_widget_set_sensitive (dialog->select_button, desc != NULL);
-
-  if (desc)
-    pango_font_description_free (desc);
-}
-
-
 static void
 gtk_font_chooser_dialog_init (GtkFontChooserDialog *dialog)
 {


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