summaryrefslogtreecommitdiff
path: root/libappstream-glib/as-app.c
diff options
context:
space:
mode:
authorKalev Lember <klember@redhat.com>2019-01-04 13:09:39 +0100
committerKalev Lember <klember@redhat.com>2019-01-04 13:16:12 +0100
commit59664c23f0cca8786ccef8423971a1eb5709d6d0 (patch)
treef6d34025ab098f5b5584fab540d72444f26c81d4 /libappstream-glib/as-app.c
parent425d551d2f357335aaa5adcee311579a2aec6acb (diff)
downloadappstream-glib-59664c23f0cca8786ccef8423971a1eb5709d6d0.tar.gz
app: Add locking to unique id building
This fixes crashes in gnome-software when concurrently calling as_app_get_unique_id() from multiple threads. https://bugzilla.redhat.com/show_bug.cgi?id=1655775 https://bugzilla.redhat.com/show_bug.cgi?id=1643702 https://bugzilla.redhat.com/show_bug.cgi?id=1640446 https://bugzilla.redhat.com/show_bug.cgi?id=1530719
Diffstat (limited to 'libappstream-glib/as-app.c')
-rw-r--r--libappstream-glib/as-app.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/libappstream-glib/as-app.c b/libappstream-glib/as-app.c
index 2210caa..5604c5d 100644
--- a/libappstream-glib/as-app.c
+++ b/libappstream-glib/as-app.c
@@ -112,6 +112,7 @@ typedef struct
AsRefString *update_contact;
gchar *unique_id;
gboolean unique_id_valid;
+ GMutex unique_id_mutex;
AsRefString *branch;
gint priority;
gsize token_cache_valid;
@@ -441,6 +442,7 @@ as_app_finalize (GObject *object)
if (priv->update_contact != NULL)
as_ref_string_unref (priv->update_contact);
g_free (priv->unique_id);
+ g_mutex_clear (&priv->unique_id_mutex);
if (priv->branch != NULL)
as_ref_string_unref (priv->branch);
g_hash_table_unref (priv->comments);
@@ -654,6 +656,11 @@ const gchar *
as_app_get_unique_id (AsApp *app)
{
AsAppPrivate *priv = GET_PRIVATE (app);
+ g_autoptr(GMutexLocker) locker = NULL;
+
+ g_return_val_if_fail (AS_IS_APP (app), NULL);
+
+ locker = g_mutex_locker_new (&priv->unique_id_mutex);
if (priv->unique_id == NULL || !priv->unique_id_valid) {
g_free (priv->unique_id);
if (as_app_has_quirk (app, AS_APP_QUIRK_MATCH_ANY_PREFIX)) {