fontbutton: Destroy dialog in unrealize()
authorBenjamin Otte <otte@redhat.com>
Mon, 23 Aug 2021 03:55:56 +0000 (05:55 +0200)
committerMatthias Clasen <mclasen@redhat.com>
Thu, 2 Sep 2021 23:59:41 +0000 (19:59 -0400)
This way, we can be sure it's always using the right display.

We can also be sure that it doesn't leak.

gtk/gtkfontbutton.c

index aad99d186b849458964a97b4e338847c83aa0fd1..fe125fd84ddab256108d71d3507ea3346464d954 100644 (file)
@@ -461,6 +461,16 @@ gtk_font_button_activate (GtkFontButton *self)
   gtk_widget_activate (self->button);
 }
 
+static void
+gtk_font_button_unrealize (GtkWidget *widget)
+{
+  GtkFontButton *font_button = GTK_FONT_BUTTON (widget);
+
+  g_clear_pointer ((GtkWindow **) &font_button->font_dialog, gtk_window_destroy);
+
+  GTK_WIDGET_CLASS (gtk_font_button_parent_class)->unrealize (widget);
+}
+
 static void
 gtk_font_button_class_init (GtkFontButtonClass *klass)
 {
@@ -476,6 +486,7 @@ gtk_font_button_class_init (GtkFontButtonClass *klass)
 
   widget_class->grab_focus = gtk_widget_grab_focus_child;
   widget_class->focus = gtk_widget_focus_child;
+  widget_class->unrealize = gtk_font_button_unrealize;
 
   klass->font_set = NULL;
   klass->activate = gtk_font_button_activate;
@@ -628,9 +639,6 @@ gtk_font_button_finalize (GObject *object)
 {
   GtkFontButton *font_button = GTK_FONT_BUTTON (object);
 
-  if (font_button->font_dialog != NULL)
-    gtk_window_destroy (GTK_WINDOW (font_button->font_dialog));
-
   g_free (font_button->title);
 
   clear_font_data (font_button);