Merge branch 'content-type-locking' into 'main'

gcontenttype: Fix a potential use-after-free of xdgmime data

See merge request GNOME/glib!2786
This commit is contained in:
Marco Trevisan 2022-06-30 15:01:41 +00:00
commit 777f0975f9

View File

@ -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,20 +501,25 @@ 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 g_steal_pointer (&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);
return comment;
return g_steal_pointer (&comment);
}
/**