[gnome-software] Make sure to call gs_profile_stop on error paths



commit c7070d8208b21e1ccd6a180f063d903746c7a601
Author: Kalev Lember <kalevlember gmail com>
Date:   Sun Oct 5 12:51:33 2014 +0200

    Make sure to call gs_profile_stop on error paths
    
    ... to ensure that gs_plugin_start() and gs_plugin_stop() calls are
    always matched.
    
    This should help with some of the profile spam reported in
    https://bugzilla.gnome.org/show_bug.cgi?id=737822

 src/gs-cmd.c                              |    2 +-
 src/gs-plugin-loader.c                    |   32 +++++++++++++++++++++-------
 src/plugins/gs-plugin-appstream.c         |   24 +++++++++------------
 src/plugins/gs-plugin-packagekit-refine.c |   21 +++++++++++++-----
 4 files changed, 50 insertions(+), 29 deletions(-)
---
diff --git a/src/gs-cmd.c b/src/gs-cmd.c
index b8272cc..047fac3 100644
--- a/src/gs-cmd.c
+++ b/src/gs-cmd.c
@@ -406,9 +406,9 @@ main (int argc, char **argv)
                gs_cmd_show_results_apps (list);
                gs_cmd_show_results_categories (categories);
        }
+out:
        gs_profile_stop (profile, "GsCmd");
        gs_profile_dump (profile);
-out:
        g_option_context_free (context);
        g_free (refine_flags_str);
        g_strfreev (split);
diff --git a/src/gs-plugin-loader.c b/src/gs-plugin-loader.c
index 6414ab6..5a6b75a 100644
--- a/src/gs-plugin-loader.c
+++ b/src/gs-plugin-loader.c
@@ -1583,7 +1583,7 @@ gs_plugin_loader_search_thread_cb (GTask *task,
 {
        const gchar *function_name = "gs_plugin_add_search";
        gboolean ret = TRUE;
-       gchar *profile_id;
+       gchar *profile_id = NULL;
        GError *error = NULL;
        GsPluginLoaderAsyncState *state = (GsPluginLoaderAsyncState *) task_data;
        GsPluginLoader *plugin_loader = GS_PLUGIN_LOADER (object);
@@ -1616,7 +1616,7 @@ gs_plugin_loader_search_thread_cb (GTask *task,
                }
                gs_plugin_status_update (plugin, NULL, GS_PLUGIN_STATUS_FINISHED);
                gs_profile_stop (plugin_loader->priv->profile, profile_id);
-               g_free (profile_id);
+               g_clear_pointer (&profile_id, g_free);
        }
 
        /* dedupe applications we already know about */
@@ -1658,6 +1658,10 @@ gs_plugin_loader_search_thread_cb (GTask *task,
        /* success */
        g_task_return_pointer (task, gs_plugin_list_copy (state->list), (GDestroyNotify) gs_plugin_list_free);
 out:
+       if (profile_id != NULL) {
+               gs_profile_stop (plugin_loader->priv->profile, profile_id);
+               g_free (profile_id);
+       }
        g_strfreev (values);
 }
 
@@ -1749,7 +1753,7 @@ gs_plugin_loader_get_categories_thread_cb (GTask *task,
 {
        const gchar *function_name = "gs_plugin_add_categories";
        gboolean ret = TRUE;
-       gchar *profile_id;
+       gchar *profile_id = NULL;
        GError *error = NULL;
        GsPluginLoaderAsyncState *state = (GsPluginLoaderAsyncState *) task_data;
        GsPluginLoader *plugin_loader = GS_PLUGIN_LOADER (object);
@@ -1781,7 +1785,7 @@ gs_plugin_loader_get_categories_thread_cb (GTask *task,
                }
                gs_plugin_status_update (plugin, NULL, GS_PLUGIN_STATUS_FINISHED);
                gs_profile_stop (plugin_loader->priv->profile, profile_id);
-               g_free (profile_id);
+               g_clear_pointer (&profile_id, g_free);
        }
 
        /* sort by name */
@@ -1801,6 +1805,10 @@ gs_plugin_loader_get_categories_thread_cb (GTask *task,
        /* success */
        g_task_return_pointer (task, gs_plugin_list_copy (state->list), (GDestroyNotify) gs_plugin_list_free);
 out:
+       if (profile_id != NULL) {
+               gs_profile_stop (plugin_loader->priv->profile, profile_id);
+               g_free (profile_id);
+       }
        return;
 }
 
@@ -1865,7 +1873,7 @@ gs_plugin_loader_get_category_apps_thread_cb (GTask *task,
 {
        const gchar *function_name = "gs_plugin_add_category_apps";
        gboolean ret = TRUE;
-       gchar *profile_id;
+       gchar *profile_id = NULL;
        GError *error = NULL;
        GsPluginLoaderAsyncState *state = (GsPluginLoaderAsyncState *) task_data;
        GsPluginLoader *plugin_loader = GS_PLUGIN_LOADER (object);
@@ -1896,7 +1904,7 @@ gs_plugin_loader_get_category_apps_thread_cb (GTask *task,
                }
                gs_plugin_status_update (plugin, NULL, GS_PLUGIN_STATUS_FINISHED);
                gs_profile_stop (plugin_loader->priv->profile, profile_id);
-               g_free (profile_id);
+               g_clear_pointer (&profile_id, g_free);
        }
 
        /* dedupe applications we already know about */
@@ -1933,6 +1941,10 @@ gs_plugin_loader_get_category_apps_thread_cb (GTask *task,
        /* success */
        g_task_return_pointer (task, gs_plugin_list_copy (state->list), (GDestroyNotify) gs_plugin_list_free);
 out:
+       if (profile_id != NULL) {
+               gs_profile_stop (plugin_loader->priv->profile, profile_id);
+               g_free (profile_id);
+       }
        return;
 }
 
@@ -3202,7 +3214,7 @@ gs_plugin_loader_filename_to_app_thread_cb (GTask *task,
 {
        const gchar *function_name = "gs_plugin_filename_to_app";
        gboolean ret = TRUE;
-       gchar *profile_id;
+       gchar *profile_id = NULL;
        GError *error = NULL;
        GsPluginLoaderAsyncState *state = (GsPluginLoaderAsyncState *) task_data;
        GsPluginLoader *plugin_loader = GS_PLUGIN_LOADER (object);
@@ -3233,7 +3245,7 @@ gs_plugin_loader_filename_to_app_thread_cb (GTask *task,
                }
                gs_plugin_status_update (plugin, NULL, GS_PLUGIN_STATUS_FINISHED);
                gs_profile_stop (plugin_loader->priv->profile, profile_id);
-               g_free (profile_id);
+               g_clear_pointer (&profile_id, g_free);
        }
 
        /* dedupe applications we already know about */
@@ -3272,6 +3284,10 @@ gs_plugin_loader_filename_to_app_thread_cb (GTask *task,
        }
        g_task_return_pointer (task, g_object_ref (state->list->data), (GDestroyNotify) g_object_unref);
 out:
+       if (profile_id != NULL) {
+               gs_profile_stop (plugin_loader->priv->profile, profile_id);
+               g_free (profile_id);
+       }
        return;
 }
 
diff --git a/src/plugins/gs-plugin-appstream.c b/src/plugins/gs-plugin-appstream.c
index dd5f362..4214f62 100644
--- a/src/plugins/gs-plugin-appstream.c
+++ b/src/plugins/gs-plugin-appstream.c
@@ -832,23 +832,19 @@ gs_plugin_refine (GsPlugin *plugin,
        for (l = *list; l != NULL; l = l->next) {
                app = GS_APP (l->data);
                ret = gs_plugin_refine_from_id (plugin, app, &found, error);
-               if (!ret) {
-                       gs_profile_stop (plugin->profile, "appstream::refine");
+               if (!ret)
                        goto out;
-               }
                if (!found) {
                        ret = gs_plugin_refine_from_pkgname (plugin, app, error);
-                       if (!ret) {
-                               gs_profile_stop (plugin->profile, "appstream::refine");
+                       if (!ret)
                                goto out;
-                       }
                }
        }
-       gs_profile_stop (plugin->profile, "appstream::refine");
 
        /* sucess */
        ret = TRUE;
 out:
+       gs_profile_stop (plugin->profile, "appstream::refine");
        return ret;
 }
 
@@ -911,8 +907,8 @@ gs_plugin_add_category_apps (GsPlugin *plugin,
                gs_plugin_add_app (list, app);
                g_object_unref (app);
        }
-       gs_profile_stop (plugin->profile, "appstream::add-category-apps");
 out:
+       gs_profile_stop (plugin->profile, "appstream::add-category-apps");
        return ret;
 }
 
@@ -1021,8 +1017,8 @@ gs_plugin_add_search (GsPlugin *plugin,
                if (!ret)
                        goto out;
        }
-       gs_profile_stop (plugin->profile, "appstream::search");
 out:
+       gs_profile_stop (plugin->profile, "appstream::search");
        return ret;
 }
 
@@ -1063,8 +1059,8 @@ gs_plugin_add_installed (GsPlugin *plugin,
                        g_object_unref (app);
                }
        }
-       gs_profile_stop (plugin->profile, "appstream::add_installed");
 out:
+       gs_profile_stop (plugin->profile, "appstream::add_installed");
        return ret;
 }
 
@@ -1147,8 +1143,8 @@ gs_plugin_add_categories (GsPlugin *plugin,
                        continue;
                gs_plugin_add_categories_for_app (*list, app);
        }
-       gs_profile_stop (plugin->profile, "appstream::add-categories");
 out:
+       gs_profile_stop (plugin->profile, "appstream::add-categories");
        return ret;
 }
 
@@ -1301,8 +1297,8 @@ gs_plugin_add_popular_by_cat (GsPlugin *plugin,
                }
 
        }
-       gs_profile_stop (plugin->profile, "appstream::add_popular[cat]");
 out:
+       gs_profile_stop (plugin->profile, "appstream::add_popular[cat]");
        if (ignore_cats != NULL)
                g_hash_table_unref (ignore_cats);
        return ret;
@@ -1375,8 +1371,8 @@ gs_plugin_add_popular_by_source (GsPlugin *plugin,
                }
                g_object_unref (app);
        }
-       gs_profile_stop (plugin->profile, "appstream::add_popular[source]");
 out:
+       gs_profile_stop (plugin->profile, "appstream::add_popular[source]");
        if (installed != NULL)
                g_hash_table_unref (installed);
        return ret;
@@ -1446,8 +1442,8 @@ gs_plugin_add_popular (GsPlugin *plugin,
                        goto out;
        }
 
-       gs_profile_stop (plugin->profile, "appstream::add_popular");
 out:
+       gs_profile_stop (plugin->profile, "appstream::add_popular");
        if (ignore_apps != NULL)
                g_hash_table_unref (ignore_apps);
        return ret;
diff --git a/src/plugins/gs-plugin-packagekit-refine.c b/src/plugins/gs-plugin-packagekit-refine.c
index 913a6ec..b8aa28f 100644
--- a/src/plugins/gs-plugin-packagekit-refine.c
+++ b/src/plugins/gs-plugin-packagekit-refine.c
@@ -748,6 +748,7 @@ gs_plugin_refine (GsPlugin *plugin,
        GList *updatedetails_all = NULL;
        GPtrArray *sources;
        GsApp *app;
+       const gchar *profile_id = NULL;
        const gchar *tmp;
        gboolean ret = TRUE;
 
@@ -762,7 +763,8 @@ gs_plugin_refine (GsPlugin *plugin,
        }
 
        /* can we resolve in one go? */
-       gs_profile_start (plugin->profile, "packagekit-refine[name->id]");
+       profile_id = "packagekit-refine[name->id]";
+       gs_profile_start (plugin->profile, profile_id);
        for (l = *list; l != NULL; l = l->next) {
                app = GS_APP (l->data);
                if (gs_app_get_id_kind (app) == AS_ID_KIND_WEB_APP)
@@ -784,10 +786,12 @@ gs_plugin_refine (GsPlugin *plugin,
                if (!ret)
                        goto out;
        }
-       gs_profile_stop (plugin->profile, "packagekit-refine[name->id]");
+       gs_profile_stop (plugin->profile, profile_id);
+       profile_id = NULL;
 
        /* set the package-id for an installed desktop file */
-       gs_profile_start (plugin->profile, "packagekit-refine[desktop-filename->id]");
+       profile_id = "packagekit-refine[desktop-filename->id]";
+       gs_profile_start (plugin->profile, profile_id);
        for (l = *list; l != NULL; l = l->next) {
                if ((flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_SETUP_ACTION) == 0)
                        continue;
@@ -805,10 +809,12 @@ gs_plugin_refine (GsPlugin *plugin,
                if (!ret)
                        goto out;
        }
-       gs_profile_stop (plugin->profile, "packagekit-refine[desktop-filename->id]");
+       gs_profile_stop (plugin->profile, profile_id);
+       profile_id = NULL;
 
        /* any update details missing? */
-       gs_profile_start (plugin->profile, "packagekit-refine[id->update-details]");
+       profile_id = "packagekit-refine[id->update-details]";
+       gs_profile_start (plugin->profile, profile_id);
        for (l = *list; l != NULL; l = l->next) {
                app = GS_APP (l->data);
                if (gs_app_get_state (app) != AS_APP_STATE_UPDATABLE)
@@ -824,7 +830,8 @@ gs_plugin_refine (GsPlugin *plugin,
                if (!ret)
                        goto out;
        }
-       gs_profile_stop (plugin->profile, "packagekit-refine[id->update-details]");
+       gs_profile_stop (plugin->profile, profile_id);
+       profile_id = NULL;
 
        /* any important details missing? */
        if ((flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_LICENCE) > 0 ||
@@ -839,6 +846,8 @@ gs_plugin_refine (GsPlugin *plugin,
                        goto out;
        }
 out:
+       if (profile_id != NULL)
+               gs_profile_stop (plugin->profile, profile_id);
        g_list_free (resolve_all);
        g_list_free (updatedetails_all);
        return ret;


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