From ea9aa8ed8259a1e0693c671b01661e423d2bea47 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Tue, 13 Sep 2022 08:54:09 -0400 Subject: [PATCH] Fix a critical in GtkFontChooserWidget When the level doesn't include the style, we need to work a bit harder to really get a face object here. Fixes: #5173 --- gtk/gtkfontchooserwidget.c | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/gtk/gtkfontchooserwidget.c b/gtk/gtkfontchooserwidget.c index bcccacbc96..50f3b2ff5b 100644 --- a/gtk/gtkfontchooserwidget.c +++ b/gtk/gtkfontchooserwidget.c @@ -963,27 +963,29 @@ gtk_font_chooser_widget_load_fonts (GtkFontChooserWidget *fontchooser, if ((priv->level & GTK_FONT_CHOOSER_LEVEL_STYLE) == 0) { GtkDelayedFontDescription *desc; - PangoFontFace *face; + PangoFontFace *face = NULL; #if PANGO_VERSION_CHECK(1,46,0) face = pango_font_family_get_face (families[i], NULL); -#else - { - PangoFontFace **faces; - int j, n_faces; - pango_font_family_list_faces (families[i], &faces, &n_faces); - face = faces[0]; - for (j = 0; j < n_faces; j++) - { - if (strcmp (pango_font_face_get_face_name (faces[j]), "Regular") == 0) - { - face = faces[j]; - break; - } - } - g_free (faces); - } #endif + if (!face) + { + PangoFontFace **faces; + int j, n_faces; + pango_font_family_list_faces (families[i], &faces, &n_faces); + face = faces[0]; + for (j = 0; j < n_faces; j++) + { + if (strcmp (pango_font_face_get_face_name (faces[j]), "Regular") == 0) + { + face = faces[j]; + break; + } + } + + g_free (faces); + } + desc = gtk_delayed_font_description_new (face); gtk_list_store_insert_with_values (list_store, &iter, -1,