diff --git a/gio/gcontenttype.c b/gio/gcontenttype.c index 170bb4341..665668890 100644 --- a/gio/gcontenttype.c +++ b/gio/gcontenttype.c @@ -486,6 +486,7 @@ gchar * g_content_type_get_description (const gchar *type) { static GHashTable *type_comment_cache = NULL; + gchar *type_copy = NULL; gchar *comment; g_return_val_if_fail (type != NULL, NULL); @@ -500,16 +501,21 @@ g_content_type_get_description (const gchar *type) comment = g_hash_table_lookup (type_comment_cache, type); comment = g_strdup (comment); - G_UNLOCK (gio_xdgmime); if (comment != NULL) - return comment; + { + G_UNLOCK (gio_xdgmime); + return comment; + } - comment = load_comment_for_mime (type); + type_copy = g_strdup (type); + G_UNLOCK (gio_xdgmime); + comment = load_comment_for_mime (type_copy); G_LOCK (gio_xdgmime); + g_hash_table_insert (type_comment_cache, - g_strdup (type), + g_steal_pointer (&type_copy), g_strdup (comment)); G_UNLOCK (gio_xdgmime);