[gnome-software] GsApp: Avoid dereferencing priv before g_return_if_fail checks
- From: Kalev Lember <klember src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] GsApp: Avoid dereferencing priv before g_return_if_fail checks
- Date: Thu, 11 Jan 2018 21:36:27 +0000 (UTC)
commit 53d502dad1943d2a169fc080f049932648a3a47b
Author: Kalev Lember <klember redhat com>
Date: Thu Jan 11 22:35:09 2018 +0100
GsApp: Avoid dereferencing priv before g_return_if_fail checks
We had a common pattern throughout the file to do:
GsAppPrivate *priv = gs_app_get_instance_private (app);
g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&priv->mutex);
g_return_if_fail (GS_IS_APP (app));
... which led to crashes when app was NULL, as g_return_if_fail was
never reached in that case. This commit reorders this so that we first
do the g_return_if_fail check and only then dereference priv.
lib/gs-app.c | 163 ++++++++++++++++++++++++++++++++++++++++-----------------
1 files changed, 114 insertions(+), 49 deletions(-)
---
diff --git a/lib/gs-app.c b/lib/gs-app.c
index d629cb7..e5ceb45 100644
--- a/lib/gs-app.c
+++ b/lib/gs-app.c
@@ -693,8 +693,9 @@ void
gs_app_set_id (GsApp *app, const gchar *id)
{
GsAppPrivate *priv = gs_app_get_instance_private (app);
- g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&priv->mutex);
+ g_autoptr(GMutexLocker) locker = NULL;
g_return_if_fail (GS_IS_APP (app));
+ locker = g_mutex_locker_new (&priv->mutex);
if (_g_set_str (&priv->id, id))
priv->unique_id_valid = FALSE;
}
@@ -1031,8 +1032,9 @@ void
gs_app_set_progress (GsApp *app, guint percentage)
{
GsAppPrivate *priv = gs_app_get_instance_private (app);
- g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&priv->mutex);
+ g_autoptr(GMutexLocker) locker = NULL;
g_return_if_fail (GS_IS_APP (app));
+ locker = g_mutex_locker_new (&priv->mutex);
if (priv->progress == percentage)
return;
if (percentage > 100) {
@@ -1059,8 +1061,9 @@ void
gs_app_set_allow_cancel (GsApp *app, gboolean allow_cancel)
{
GsAppPrivate *priv = gs_app_get_instance_private (app);
- g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&priv->mutex);
+ g_autoptr(GMutexLocker) locker = NULL;
g_return_if_fail (GS_IS_APP (app));
+ locker = g_mutex_locker_new (&priv->mutex);
if (priv->allow_cancel == allow_cancel)
return;
priv->allow_cancel = allow_cancel;
@@ -1095,9 +1098,11 @@ void
gs_app_set_state (GsApp *app, AsAppState state)
{
GsAppPrivate *priv = gs_app_get_instance_private (app);
- g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&priv->mutex);
+ g_autoptr(GMutexLocker) locker = NULL;
g_return_if_fail (GS_IS_APP (app));
+ locker = g_mutex_locker_new (&priv->mutex);
+
if (gs_app_set_state_internal (app, state))
gs_app_queue_notify (app, "state");
}
@@ -1142,10 +1147,12 @@ gs_app_set_kind (GsApp *app, AsAppKind kind)
{
GsAppPrivate *priv = gs_app_get_instance_private (app);
gboolean state_change_ok = FALSE;
- g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&priv->mutex);
+ g_autoptr(GMutexLocker) locker = NULL;
g_return_if_fail (GS_IS_APP (app));
+ locker = g_mutex_locker_new (&priv->mutex);
+
/* same */
if (priv->kind == kind)
return;
@@ -1209,8 +1216,9 @@ const gchar *
gs_app_get_unique_id (GsApp *app)
{
GsAppPrivate *priv = gs_app_get_instance_private (app);
- g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&priv->mutex);
+ g_autoptr(GMutexLocker) locker = NULL;
g_return_val_if_fail (GS_IS_APP (app), NULL);
+ locker = g_mutex_locker_new (&priv->mutex);
return gs_app_get_unique_id_unlocked (app);
}
@@ -1227,9 +1235,11 @@ void
gs_app_set_unique_id (GsApp *app, const gchar *unique_id)
{
GsAppPrivate *priv = gs_app_get_instance_private (app);
- g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&priv->mutex);
+ g_autoptr(GMutexLocker) locker = NULL;
g_return_if_fail (GS_IS_APP (app));
+ locker = g_mutex_locker_new (&priv->mutex);
+
/* check for sanity */
if (!as_utils_unique_id_valid (unique_id))
g_warning ("unique_id %s not valid", unique_id);
@@ -1271,9 +1281,11 @@ void
gs_app_set_name (GsApp *app, GsAppQuality quality, const gchar *name)
{
GsAppPrivate *priv = gs_app_get_instance_private (app);
- g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&priv->mutex);
+ g_autoptr(GMutexLocker) locker = NULL;
g_return_if_fail (GS_IS_APP (app));
+ locker = g_mutex_locker_new (&priv->mutex);
+
/* only save this if the data is sufficiently high quality */
if (quality <= priv->name_quality)
return;
@@ -1313,8 +1325,9 @@ void
gs_app_set_branch (GsApp *app, const gchar *branch)
{
GsAppPrivate *priv = gs_app_get_instance_private (app);
- g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&priv->mutex);
+ g_autoptr(GMutexLocker) locker = NULL;
g_return_if_fail (GS_IS_APP (app));
+ locker = g_mutex_locker_new (&priv->mutex);
if (_g_set_str (&priv->branch, branch))
priv->unique_id_valid = FALSE;
}
@@ -1354,11 +1367,13 @@ gs_app_add_source (GsApp *app, const gchar *source)
GsAppPrivate *priv = gs_app_get_instance_private (app);
const gchar *tmp;
guint i;
- g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&priv->mutex);
+ g_autoptr(GMutexLocker) locker = NULL;
g_return_if_fail (GS_IS_APP (app));
g_return_if_fail (source != NULL);
+ locker = g_mutex_locker_new (&priv->mutex);
+
/* check source doesn't already exist */
for (i = 0; i < priv->sources->len; i++) {
tmp = g_ptr_array_index (priv->sources, i);
@@ -1401,8 +1416,9 @@ void
gs_app_set_sources (GsApp *app, GPtrArray *sources)
{
GsAppPrivate *priv = gs_app_get_instance_private (app);
- g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&priv->mutex);
+ g_autoptr(GMutexLocker) locker = NULL;
g_return_if_fail (GS_IS_APP (app));
+ locker = g_mutex_locker_new (&priv->mutex);
_g_set_ptr_array (&priv->sources, sources);
}
@@ -1456,8 +1472,9 @@ void
gs_app_clear_source_ids (GsApp *app)
{
GsAppPrivate *priv = gs_app_get_instance_private (app);
- g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&priv->mutex);
+ g_autoptr(GMutexLocker) locker = NULL;
g_return_if_fail (GS_IS_APP (app));
+ locker = g_mutex_locker_new (&priv->mutex);
g_ptr_array_set_size (priv->source_ids, 0);
}
@@ -1475,8 +1492,9 @@ void
gs_app_set_source_ids (GsApp *app, GPtrArray *source_ids)
{
GsAppPrivate *priv = gs_app_get_instance_private (app);
- g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&priv->mutex);
+ g_autoptr(GMutexLocker) locker = NULL;
g_return_if_fail (GS_IS_APP (app));
+ locker = g_mutex_locker_new (&priv->mutex);
_g_set_ptr_array (&priv->source_ids, source_ids);
}
@@ -1558,8 +1576,9 @@ void
gs_app_set_project_group (GsApp *app, const gchar *project_group)
{
GsAppPrivate *priv = gs_app_get_instance_private (app);
- g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&priv->mutex);
+ g_autoptr(GMutexLocker) locker = NULL;
g_return_if_fail (GS_IS_APP (app));
+ locker = g_mutex_locker_new (&priv->mutex);
_g_set_str (&priv->project_group, project_group);
}
@@ -1576,8 +1595,9 @@ void
gs_app_set_developer_name (GsApp *app, const gchar *developer_name)
{
GsAppPrivate *priv = gs_app_get_instance_private (app);
- g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&priv->mutex);
+ g_autoptr(GMutexLocker) locker = NULL;
g_return_if_fail (GS_IS_APP (app));
+ locker = g_mutex_locker_new (&priv->mutex);
_g_set_str (&priv->developer_name, developer_name);
}
@@ -1631,8 +1651,9 @@ void
gs_app_add_icon (GsApp *app, AsIcon *icon)
{
GsAppPrivate *priv = gs_app_get_instance_private (app);
- g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&priv->mutex);
+ g_autoptr(GMutexLocker) locker = NULL;
g_return_if_fail (GS_IS_APP (app));
+ locker = g_mutex_locker_new (&priv->mutex);
if (icon == NULL) {
g_ptr_array_set_size (priv->icons, 0);
return;
@@ -1673,8 +1694,9 @@ void
gs_app_set_local_file (GsApp *app, GFile *local_file)
{
GsAppPrivate *priv = gs_app_get_instance_private (app);
- g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&priv->mutex);
+ g_autoptr(GMutexLocker) locker = NULL;
g_return_if_fail (GS_IS_APP (app));
+ locker = g_mutex_locker_new (&priv->mutex);
g_set_object (&priv->local_file, local_file);
}
@@ -1709,8 +1731,9 @@ void
gs_app_set_content_rating (GsApp *app, AsContentRating *content_rating)
{
GsAppPrivate *priv = gs_app_get_instance_private (app);
- g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&priv->mutex);
+ g_autoptr(GMutexLocker) locker = NULL;
g_return_if_fail (GS_IS_APP (app));
+ locker = g_mutex_locker_new (&priv->mutex);
g_set_object (&priv->content_rating, content_rating);
}
@@ -1747,9 +1770,10 @@ void
gs_app_set_runtime (GsApp *app, GsApp *runtime)
{
GsAppPrivate *priv = gs_app_get_instance_private (app);
- g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&priv->mutex);
+ g_autoptr(GMutexLocker) locker = NULL;
g_return_if_fail (GS_IS_APP (app));
g_return_if_fail (app != runtime);
+ locker = g_mutex_locker_new (&priv->mutex);
g_set_object (&priv->runtime, runtime);
}
@@ -1786,9 +1810,10 @@ void
gs_app_set_update_runtime (GsApp *app, GsApp *runtime)
{
GsAppPrivate *priv = gs_app_get_instance_private (app);
- g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&priv->mutex);
+ g_autoptr(GMutexLocker) locker = NULL;
g_return_if_fail (GS_IS_APP (app));
g_return_if_fail (app != runtime);
+ locker = g_mutex_locker_new (&priv->mutex);
g_set_object (&priv->update_runtime, runtime);
}
@@ -1805,8 +1830,9 @@ void
gs_app_set_pixbuf (GsApp *app, GdkPixbuf *pixbuf)
{
GsAppPrivate *priv = gs_app_get_instance_private (app);
- g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&priv->mutex);
+ g_autoptr(GMutexLocker) locker = NULL;
g_return_if_fail (GS_IS_APP (app));
+ locker = g_mutex_locker_new (&priv->mutex);
g_set_object (&priv->pixbuf, pixbuf);
}
@@ -1842,8 +1868,9 @@ void
gs_app_set_price (GsApp *app, gdouble amount, const gchar *currency)
{
GsAppPrivate *priv = gs_app_get_instance_private (app);
- g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&priv->mutex);
+ g_autoptr(GMutexLocker) locker = NULL;
g_return_if_fail (GS_IS_APP (app));
+ locker = g_mutex_locker_new (&priv->mutex);
if (priv->price != NULL)
g_object_unref (priv->price);
priv->price = gs_price_new (amount, currency);
@@ -2009,9 +2036,11 @@ void
gs_app_set_version (GsApp *app, const gchar *version)
{
GsAppPrivate *priv = gs_app_get_instance_private (app);
- g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&priv->mutex);
+ g_autoptr(GMutexLocker) locker = NULL;
g_return_if_fail (GS_IS_APP (app));
+ locker = g_mutex_locker_new (&priv->mutex);
+
if (_g_set_str (&priv->version, version)) {
gs_app_ui_versions_invalidate (app);
gs_app_queue_notify (app, "version");
@@ -2050,9 +2079,11 @@ void
gs_app_set_summary (GsApp *app, GsAppQuality quality, const gchar *summary)
{
GsAppPrivate *priv = gs_app_get_instance_private (app);
- g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&priv->mutex);
+ g_autoptr(GMutexLocker) locker = NULL;
g_return_if_fail (GS_IS_APP (app));
+ locker = g_mutex_locker_new (&priv->mutex);
+
/* only save this if the data is sufficiently high quality */
if (quality <= priv->summary_quality)
return;
@@ -2093,9 +2124,11 @@ void
gs_app_set_description (GsApp *app, GsAppQuality quality, const gchar *description)
{
GsAppPrivate *priv = gs_app_get_instance_private (app);
- g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&priv->mutex);
+ g_autoptr(GMutexLocker) locker = NULL;
g_return_if_fail (GS_IS_APP (app));
+ locker = g_mutex_locker_new (&priv->mutex);
+
/* only save this if the data is sufficiently high quality */
if (quality <= priv->description_quality)
return;
@@ -2136,8 +2169,9 @@ void
gs_app_set_url (GsApp *app, AsUrlKind kind, const gchar *url)
{
GsAppPrivate *priv = gs_app_get_instance_private (app);
- g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&priv->mutex);
+ g_autoptr(GMutexLocker) locker = NULL;
g_return_if_fail (GS_IS_APP (app));
+ locker = g_mutex_locker_new (&priv->mutex);
g_hash_table_insert (priv->urls,
g_strdup (as_url_kind_to_string (kind)),
g_strdup (url));
@@ -2177,8 +2211,9 @@ void
gs_app_set_launchable (GsApp *app, AsLaunchableKind kind, const gchar *launchable)
{
GsAppPrivate *priv = gs_app_get_instance_private (app);
- g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&priv->mutex);
+ g_autoptr(GMutexLocker) locker = NULL;
g_return_if_fail (GS_IS_APP (app));
+ locker = g_mutex_locker_new (&priv->mutex);
g_hash_table_insert (priv->launchables,
g_strdup (as_launchable_kind_to_string (kind)),
g_strdup (launchable));
@@ -2251,12 +2286,14 @@ void
gs_app_set_license (GsApp *app, GsAppQuality quality, const gchar *license)
{
GsAppPrivate *priv = gs_app_get_instance_private (app);
- g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&priv->mutex);
+ g_autoptr(GMutexLocker) locker = NULL;
guint i;
g_auto(GStrv) tokens = NULL;
g_return_if_fail (GS_IS_APP (app));
+ locker = g_mutex_locker_new (&priv->mutex);
+
/* only save this if the data is sufficiently high quality */
if (quality <= priv->license_quality)
return;
@@ -2313,8 +2350,9 @@ void
gs_app_set_summary_missing (GsApp *app, const gchar *summary_missing)
{
GsAppPrivate *priv = gs_app_get_instance_private (app);
- g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&priv->mutex);
+ g_autoptr(GMutexLocker) locker = NULL;
g_return_if_fail (GS_IS_APP (app));
+ locker = g_mutex_locker_new (&priv->mutex);
_g_set_str (&priv->summary_missing, summary_missing);
}
@@ -2352,8 +2390,9 @@ void
gs_app_set_menu_path (GsApp *app, gchar **menu_path)
{
GsAppPrivate *priv = gs_app_get_instance_private (app);
- g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&priv->mutex);
+ g_autoptr(GMutexLocker) locker = NULL;
g_return_if_fail (GS_IS_APP (app));
+ locker = g_mutex_locker_new (&priv->mutex);
_g_set_strv (&priv->menu_path, menu_path);
}
@@ -2388,9 +2427,11 @@ void
gs_app_set_origin (GsApp *app, const gchar *origin)
{
GsAppPrivate *priv = gs_app_get_instance_private (app);
- g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&priv->mutex);
+ g_autoptr(GMutexLocker) locker = NULL;
g_return_if_fail (GS_IS_APP (app));
+ locker = g_mutex_locker_new (&priv->mutex);
+
/* same */
if (g_strcmp0 (origin, priv->origin) == 0)
return;
@@ -2448,13 +2489,15 @@ void
gs_app_set_origin_hostname (GsApp *app, const gchar *origin_hostname)
{
GsAppPrivate *priv = gs_app_get_instance_private (app);
- g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&priv->mutex);
+ g_autoptr(GMutexLocker) locker = NULL;
g_autoptr(SoupURI) uri = NULL;
guint i;
const gchar *prefixes[] = { "download.", "mirrors.", NULL };
g_return_if_fail (GS_IS_APP (app));
+ locker = g_mutex_locker_new (&priv->mutex);
+
/* same */
if (g_strcmp0 (origin_hostname, priv->origin_hostname) == 0)
return;
@@ -2579,8 +2622,9 @@ void
gs_app_set_update_version (GsApp *app, const gchar *update_version)
{
GsAppPrivate *priv = gs_app_get_instance_private (app);
- g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&priv->mutex);
+ g_autoptr(GMutexLocker) locker = NULL;
g_return_if_fail (GS_IS_APP (app));
+ locker = g_mutex_locker_new (&priv->mutex);
gs_app_set_update_version_internal (app, update_version);
gs_app_queue_notify (app, "version");
}
@@ -2616,8 +2660,9 @@ void
gs_app_set_update_details (GsApp *app, const gchar *update_details)
{
GsAppPrivate *priv = gs_app_get_instance_private (app);
- g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&priv->mutex);
+ g_autoptr(GMutexLocker) locker = NULL;
g_return_if_fail (GS_IS_APP (app));
+ locker = g_mutex_locker_new (&priv->mutex);
_g_set_str (&priv->update_details, update_details);
}
@@ -2699,9 +2744,11 @@ void
gs_app_set_management_plugin (GsApp *app, const gchar *management_plugin)
{
GsAppPrivate *priv = gs_app_get_instance_private (app);
- g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&priv->mutex);
+ g_autoptr(GMutexLocker) locker = NULL;
g_return_if_fail (GS_IS_APP (app));
+ locker = g_mutex_locker_new (&priv->mutex);
+
/* plugins cannot adopt wildcard packages */
if (gs_app_has_quirk (app, AS_APP_QUIRK_MATCH_ANY_PREFIX)) {
g_warning ("plugins should not set the management plugin on "
@@ -2760,8 +2807,9 @@ void
gs_app_set_rating (GsApp *app, gint rating)
{
GsAppPrivate *priv = gs_app_get_instance_private (app);
- g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&priv->mutex);
+ g_autoptr(GMutexLocker) locker = NULL;
g_return_if_fail (GS_IS_APP (app));
+ locker = g_mutex_locker_new (&priv->mutex);
if (rating == priv->rating)
return;
priv->rating = rating;
@@ -2799,8 +2847,9 @@ void
gs_app_set_review_ratings (GsApp *app, GArray *review_ratings)
{
GsAppPrivate *priv = gs_app_get_instance_private (app);
- g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&priv->mutex);
+ g_autoptr(GMutexLocker) locker = NULL;
g_return_if_fail (GS_IS_APP (app));
+ locker = g_mutex_locker_new (&priv->mutex);
_g_set_array (&priv->review_ratings, review_ratings);
}
@@ -3089,11 +3138,13 @@ void
gs_app_set_metadata_variant (GsApp *app, const gchar *key, GVariant *value)
{
GsAppPrivate *priv = gs_app_get_instance_private (app);
- g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&priv->mutex);
+ g_autoptr(GMutexLocker) locker = NULL;
GVariant *found;
g_return_if_fail (GS_IS_APP (app));
+ locker = g_mutex_locker_new (&priv->mutex);
+
/* if no value, then remove the key */
if (value == NULL) {
g_hash_table_remove (priv->metadata, key);
@@ -3155,11 +3206,13 @@ gs_app_add_addon (GsApp *app, GsApp *addon)
GsAppPrivate *priv = gs_app_get_instance_private (app);
gpointer found;
const gchar *id;
- g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&priv->mutex);
+ g_autoptr(GMutexLocker) locker = NULL;
g_return_if_fail (GS_IS_APP (app));
g_return_if_fail (GS_IS_APP (addon));
+ locker = g_mutex_locker_new (&priv->mutex);
+
id = gs_app_get_id (addon);
found = g_hash_table_lookup (priv->addons_hash, id);
if (found != NULL)
@@ -3182,9 +3235,10 @@ void
gs_app_remove_addon (GsApp *app, GsApp *addon)
{
GsAppPrivate *priv = gs_app_get_instance_private (app);
- g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&priv->mutex);
+ g_autoptr(GMutexLocker) locker = NULL;
g_return_if_fail (GS_IS_APP (app));
g_return_if_fail (GS_IS_APP (addon));
+ locker = g_mutex_locker_new (&priv->mutex);
g_hash_table_remove (priv->addons_hash, gs_app_get_id (addon));
g_ptr_array_remove (priv->addons, addon);
}
@@ -3223,10 +3277,12 @@ gs_app_add_related (GsApp *app, GsApp *app2)
GsAppPrivate *priv2 = gs_app_get_instance_private (app2);
gchar *key;
gpointer found;
- g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&priv->mutex);
+ g_autoptr(GMutexLocker) locker = NULL;
g_return_if_fail (GS_IS_APP (app));
+ locker = g_mutex_locker_new (&priv->mutex);
+
/* if the app is updatable-live and any related app is not then
* degrade to the offline state */
if (priv->state == AS_APP_STATE_UPDATABLE_LIVE &&
@@ -3278,8 +3334,9 @@ void
gs_app_add_history (GsApp *app, GsApp *app2)
{
GsAppPrivate *priv = gs_app_get_instance_private (app);
- g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&priv->mutex);
+ g_autoptr(GMutexLocker) locker = NULL;
g_return_if_fail (GS_IS_APP (app));
+ locker = g_mutex_locker_new (&priv->mutex);
g_ptr_array_add (priv->history, g_object_ref (app2));
}
@@ -3422,9 +3479,10 @@ void
gs_app_set_categories (GsApp *app, GPtrArray *categories)
{
GsAppPrivate *priv = gs_app_get_instance_private (app);
- g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&priv->mutex);
+ g_autoptr(GMutexLocker) locker = NULL;
g_return_if_fail (GS_IS_APP (app));
g_return_if_fail (categories != NULL);
+ locker = g_mutex_locker_new (&priv->mutex);
_g_set_ptr_array (&priv->categories, categories);
}
@@ -3441,9 +3499,10 @@ void
gs_app_add_category (GsApp *app, const gchar *category)
{
GsAppPrivate *priv = gs_app_get_instance_private (app);
- g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&priv->mutex);
+ g_autoptr(GMutexLocker) locker = NULL;
g_return_if_fail (GS_IS_APP (app));
g_return_if_fail (category != NULL);
+ locker = g_mutex_locker_new (&priv->mutex);
if (gs_app_has_category (app, category))
return;
g_ptr_array_add (priv->categories, g_strdup (category));
@@ -3466,10 +3525,12 @@ gs_app_remove_category (GsApp *app, const gchar *category)
GsAppPrivate *priv = gs_app_get_instance_private (app);
const gchar *tmp;
guint i;
+ g_autoptr(GMutexLocker) locker = NULL;
- g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&priv->mutex);
g_return_val_if_fail (GS_IS_APP (app), FALSE);
+ locker = g_mutex_locker_new (&priv->mutex);
+
for (i = 0; i < priv->categories->len; i++) {
tmp = g_ptr_array_index (priv->categories, i);
if (g_strcmp0 (tmp, category) != 0)
@@ -3511,9 +3572,10 @@ void
gs_app_set_key_colors (GsApp *app, GPtrArray *key_colors)
{
GsAppPrivate *priv = gs_app_get_instance_private (app);
- g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&priv->mutex);
+ g_autoptr(GMutexLocker) locker = NULL;
g_return_if_fail (GS_IS_APP (app));
g_return_if_fail (key_colors != NULL);
+ locker = g_mutex_locker_new (&priv->mutex);
_g_set_ptr_array (&priv->key_colors, key_colors);
}
@@ -3566,9 +3628,10 @@ void
gs_app_set_keywords (GsApp *app, GPtrArray *keywords)
{
GsAppPrivate *priv = gs_app_get_instance_private (app);
- g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&priv->mutex);
+ g_autoptr(GMutexLocker) locker = NULL;
g_return_if_fail (GS_IS_APP (app));
g_return_if_fail (keywords != NULL);
+ locker = g_mutex_locker_new (&priv->mutex);
_g_set_ptr_array (&priv->keywords, keywords);
}
@@ -3760,9 +3823,10 @@ void
gs_app_add_quirk (GsApp *app, AsAppQuirk quirk)
{
GsAppPrivate *priv = gs_app_get_instance_private (app);
- g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&priv->mutex);
+ g_autoptr(GMutexLocker) locker = NULL;
g_return_if_fail (GS_IS_APP (app));
+ locker = g_mutex_locker_new (&priv->mutex);
priv->quirk |= quirk;
gs_app_queue_notify (app, "quirk");
}
@@ -3780,9 +3844,10 @@ void
gs_app_remove_quirk (GsApp *app, AsAppQuirk quirk)
{
GsAppPrivate *priv = gs_app_get_instance_private (app);
- g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&priv->mutex);
+ g_autoptr(GMutexLocker) locker = NULL;
g_return_if_fail (GS_IS_APP (app));
+ locker = g_mutex_locker_new (&priv->mutex);
priv->quirk &= ~quirk;
gs_app_queue_notify (app, "quirk");
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]