From 3c4f51df70336730aa992d26548f75e2d09d7e6d Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 8 Jun 2016 15:34:44 +0200 Subject: [PATCH] Fix crash with GTK+ 2 in wxMimeTypesManager code Fix the crash introduced by 4dfde501dfbc0c1e1ffa2e4b8dd48622f98af362: we can't use g_object_unref() to free GtkIconInfo with GTK+ 2. See https://github.com/wxWidgets/wxWidgets/pull/293 --- src/gtk/mimetype.cpp | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/src/gtk/mimetype.cpp b/src/gtk/mimetype.cpp index 31ee984ec5..7edd7bded0 100644 --- a/src/gtk/mimetype.cpp +++ b/src/gtk/mimetype.cpp @@ -31,17 +31,30 @@ wxString wxGTKMimeTypesManagerImpl::GetIconFromMimeType(const wxString& mime) if ( !theme ) return wxString(); - wxGtkObject giconinfo(gtk_icon_theme_lookup_by_gicon - ( - theme, - gicon, - 256, - GTK_ICON_LOOKUP_NO_SVG - )); - if ( !giconinfo ) - return wxString(); + // Notice that we can't use wxGtkObject here because a special function + // needs to be used for freeing this object in GTK+ 2. We should switch to + // using wxGtkObject when support for GTK+ 2 is dropped. + GtkIconInfo* const giconinfo = gtk_icon_theme_lookup_by_gicon + ( + theme, + gicon, + 256, + GTK_ICON_LOOKUP_NO_SVG + ); - return wxString::FromUTF8(gtk_icon_info_get_filename(giconinfo)); + wxString icon; + if ( giconinfo ) + { + icon = wxString::FromUTF8(gtk_icon_info_get_filename(giconinfo)); + +#ifdef __WXGTK3__ + g_object_unref(giconinfo); +#else + gtk_icon_info_free(giconinfo); +#endif + } + + return icon; } wxMimeTypesManagerImpl *wxGTKMimeTypesManagerFactory::CreateMimeTypesManagerImpl()