[gnome-software] GsPlugin: Avoid dereferencing self pointer before g_return_if_fail checks



commit 76aa7f960d8026ad39ad73cfa7a8a50d9d08edeb
Author: Kalev Lember <klember redhat com>
Date:   Fri Jan 12 10:19:03 2018 +0100

    GsPlugin: Avoid dereferencing self pointer before g_return_if_fail checks

 lib/gs-plugin.c |   15 +++++++++++----
 1 files changed, 11 insertions(+), 4 deletions(-)
---
diff --git a/lib/gs-plugin.c b/lib/gs-plugin.c
index fb8c450..6bf9402 100644
--- a/lib/gs-plugin.c
+++ b/lib/gs-plugin.c
@@ -1503,11 +1503,13 @@ gs_plugin_cache_lookup (GsPlugin *plugin, const gchar *key)
 {
        GsPluginPrivate *priv = gs_plugin_get_instance_private (plugin);
        GsApp *app;
-       g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&priv->cache_mutex);
+       g_autoptr(GMutexLocker) locker = NULL;
 
        g_return_val_if_fail (GS_IS_PLUGIN (plugin), NULL);
        g_return_val_if_fail (key != NULL, NULL);
 
+       locker = g_mutex_locker_new (&priv->cache_mutex);
+
        /* global, so using a unique_id */
        if (gs_plugin_has_flags (plugin, GS_PLUGIN_FLAGS_GLOBAL_CACHE)) {
                if (!as_utils_unique_id_valid (key)) {
@@ -1536,11 +1538,13 @@ void
 gs_plugin_cache_remove (GsPlugin *plugin, const gchar *key)
 {
        GsPluginPrivate *priv = gs_plugin_get_instance_private (plugin);
-       g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&priv->cache_mutex);
+       g_autoptr(GMutexLocker) locker = NULL;
 
        g_return_if_fail (GS_IS_PLUGIN (plugin));
        g_return_if_fail (key != NULL);
 
+       locker = g_mutex_locker_new (&priv->cache_mutex);
+
        /* global, so using internal unique_id */
        if (gs_plugin_has_flags (plugin, GS_PLUGIN_FLAGS_GLOBAL_CACHE)) {
                GsApp *app_tmp;
@@ -1571,11 +1575,13 @@ void
 gs_plugin_cache_add (GsPlugin *plugin, const gchar *key, GsApp *app)
 {
        GsPluginPrivate *priv = gs_plugin_get_instance_private (plugin);
-       g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&priv->cache_mutex);
+       g_autoptr(GMutexLocker) locker = NULL;
 
        g_return_if_fail (GS_IS_PLUGIN (plugin));
        g_return_if_fail (GS_IS_APP (app));
 
+       locker = g_mutex_locker_new (&priv->cache_mutex);
+
        /* default */
        if (key == NULL)
                key = gs_app_get_unique_id (app);
@@ -1615,10 +1621,11 @@ void
 gs_plugin_cache_invalidate (GsPlugin *plugin)
 {
        GsPluginPrivate *priv = gs_plugin_get_instance_private (plugin);
-       g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&priv->cache_mutex);
+       g_autoptr(GMutexLocker) locker = NULL;
 
        g_return_if_fail (GS_IS_PLUGIN (plugin));
 
+       locker = g_mutex_locker_new (&priv->cache_mutex);
        g_hash_table_remove_all (priv->cache);
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]