# HG changeset patch # User bsmith@81767d24-ef19-dc11-ae90-00e081727c95 # Date 1611517134 0 # Node ID 14a1e07e8f4e41ff70722594dd8d8198b512a5d8 # Parent 4fb54b9fcf782669695c4935689b6af7281c92d0 GTK2: Fix crash when calling dw_window_set_font() with NULL font name. Also there seemed to be some logic errors in the existing code, it did not seem to use the pango style font name after converting to it. diff -r 4fb54b9fcf78 -r 14a1e07e8f4e gtk/dw.c --- a/gtk/dw.c Sun Jan 24 19:27:16 2021 +0000 +++ b/gtk/dw.c Sun Jan 24 19:38:54 2021 +0000 @@ -3167,7 +3167,7 @@ GdkFont *gdkfont; #endif GtkWidget *handle2 = handle; - char *font = strdup(fontname); + char *font = fontname ? strdup(fontname) : NULL; int _locked_by_me = FALSE; gpointer data; @@ -3203,13 +3203,18 @@ /* Free old font if it exists */ gdkfont = (GdkFont *)gtk_object_get_data(GTK_OBJECT(handle2), "_dw_gdkfont"); if(gdkfont) + { gdk_font_unref(gdkfont); - gdkfont = gdk_font_load(fontname); + gdkfont = NULL; + } + if(fontname) + gdkfont = gdk_font_load(fontname); if(!gdkfont) gdkfont = gdk_font_load("fixed"); gtk_object_set_data(GTK_OBJECT(handle2), "_dw_gdkfont", (gpointer)gdkfont); #else - _convert_font(font); + if(font) + _convert_font(font); #endif /* Free old font name if one is allocated */ @@ -3219,13 +3224,13 @@ free(data); #if GTK_MAJOR_VERSION > 1 - pfont = pango_font_description_from_string(fontname); - - if(pfont) + if(font && (pfont = pango_font_description_from_string(font))) { gtk_widget_modify_font(handle2, pfont); pango_font_description_free(pfont); } + else + gtk_widget_modify_font(handle2, NULL); #endif DW_MUTEX_UNLOCK; return TRUE;