[gnome-software] Use __attribute__(cleanup) in more code
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] Use __attribute__(cleanup) in more code
- Date: Fri, 12 Dec 2014 12:21:54 +0000 (UTC)
commit 24be1ec4f15c48b46a418a58f1201f0da7d69ab5
Author: Richard Hughes <richard hughsie com>
Date: Fri Dec 12 09:56:13 2014 +0000
Use __attribute__(cleanup) in more code
src/gs-app-addon-row.c | 26 +--
src/gs-app-folder-dialog.c | 37 ++--
src/gs-app-row.c | 47 ++--
src/gs-app-tile.c | 30 +-
src/gs-app.c | 25 +-
src/gs-application.c | 50 ++--
src/gs-box.c | 6 +-
src/gs-cmd.c | 59 ++---
src/gs-dbus-helper.c | 48 +---
src/gs-feature-tile.c | 90 +++----
src/gs-first-run-dialog.c | 4 +-
src/gs-folders.c | 115 ++++-----
src/gs-history-dialog.c | 53 ++--
src/gs-main.c | 7 +-
src/gs-markdown.c | 117 +++------
src/gs-offline-updates.c | 22 +-
src/gs-plugin-loader.c | 352 ++++++++++---------------
src/gs-plugin.c | 35 +--
src/gs-popular-tile.c | 12 +-
src/gs-profile.c | 7 +-
src/gs-proxy-settings.c | 55 ++---
src/gs-screenshot-image.c | 106 +++-----
src/gs-self-test.c | 50 +---
src/gs-shell-category.c | 13 +-
src/gs-shell-details.c | 136 ++++------
src/gs-shell-installed.c | 97 +++----
src/gs-shell-overview.c | 17 +-
src/gs-shell-search-provider.c | 76 +++---
src/gs-shell-search.c | 72 ++----
src/gs-shell-updates.c | 84 +++----
src/gs-shell.c | 43 ++--
src/gs-sources-dialog.c | 44 ++--
src/gs-update-dialog.c | 92 +++----
src/gs-update-list.c | 41 ++--
src/gs-update-monitor.c | 89 +++----
src/gs-utils.c | 37 +--
src/plugins/gs-moduleset.c | 26 +--
src/plugins/gs-plugin-appstream.c | 100 ++-----
src/plugins/gs-plugin-fedora-tagger-ratings.c | 164 ++++--------
src/plugins/gs-plugin-fedora-tagger-usage.c | 45 +--
src/plugins/gs-plugin-hardcoded-categories.c | 4 +-
src/plugins/gs-plugin-hardcoded-featured.c | 62 ++---
src/plugins/gs-plugin-local-ratings.c | 42 +--
src/plugins/gs-plugin-menu-spec-categories.c | 3 +-
src/plugins/gs-plugin-menu-spec-refine.c | 13 +-
src/plugins/gs-plugin-moduleset.c | 28 +--
src/plugins/gs-plugin-packagekit-history.c | 59 ++---
src/plugins/gs-plugin-packagekit-offline.c | 34 +--
src/plugins/gs-plugin-packagekit-refine.c | 145 +++-------
src/plugins/gs-plugin-packagekit-refresh.c | 75 ++----
src/plugins/gs-plugin-packagekit.c | 131 +++-------
src/plugins/gs-plugin-systemd-updates.c | 26 +--
src/plugins/gs-self-test.c | 5 +-
src/plugins/packagekit-common.c | 26 +--
54 files changed, 1184 insertions(+), 1998 deletions(-)
---
diff --git a/src/gs-app-addon-row.c b/src/gs-app-addon-row.c
index 0bb6151..6086fdd 100644
--- a/src/gs-app-addon-row.c
+++ b/src/gs-app-addon-row.c
@@ -54,9 +54,8 @@ static GString *
gs_app_addon_row_get_summary (GsAppAddonRow *row)
{
GsAppAddonRowPrivate *priv = row->priv;
- GString *str = NULL;
const gchar *tmp = NULL;
- gchar *escaped;
+ _cleanup_free_ gchar *escaped = NULL;
/* try all these things in order */
if (gs_app_get_kind (priv->app) == GS_APP_KIND_MISSING)
@@ -67,17 +66,14 @@ gs_app_addon_row_get_summary (GsAppAddonRow *row)
tmp = gs_app_get_description (priv->app);
escaped = g_markup_escape_text (tmp, -1);
- str = g_string_new (escaped);
- g_free (escaped);
-
- return str;
+ return g_string_new (escaped);
}
void
gs_app_addon_row_refresh (GsAppAddonRow *row)
{
GsAppAddonRowPrivate *priv = row->priv;
- GString *str;
+ _cleanup_string_free_ GString *str = NULL;
if (row->priv->app == NULL)
return;
@@ -86,10 +82,8 @@ gs_app_addon_row_refresh (GsAppAddonRow *row)
str = gs_app_addon_row_get_summary (row);
gs_string_replace (str, "\n", " ");
gtk_label_set_markup (GTK_LABEL (priv->description_label), str->str);
- g_string_free (str, TRUE);
-
gtk_label_set_label (GTK_LABEL (priv->name_label),
- gs_app_get_name (priv->app));
+ gs_app_get_name (priv->app));
/* update the state label */
switch (gs_app_get_state (row->priv->app)) {
@@ -166,8 +160,8 @@ gs_app_addon_row_refresh_idle (gpointer user_data)
static void
gs_app_addon_row_notify_props_changed_cb (GsApp *app,
- GParamSpec *pspec,
- GsAppAddonRow *row)
+ GParamSpec *pspec,
+ GsAppAddonRow *row)
{
g_idle_add (gs_app_addon_row_refresh_idle, g_object_ref (row));
}
@@ -181,8 +175,8 @@ gs_app_addon_row_set_addon (GsAppAddonRow *row, GsApp *app)
row->priv->app = g_object_ref (app);
g_signal_connect_object (row->priv->app, "notify::state",
- G_CALLBACK (gs_app_addon_row_notify_props_changed_cb),
- row, 0);
+ G_CALLBACK (gs_app_addon_row_notify_props_changed_cb),
+ row, 0);
gs_app_addon_row_refresh (row);
}
@@ -243,7 +237,7 @@ gs_app_addon_row_class_init (GsAppAddonRowClass *klass)
widget_class->destroy = gs_app_addon_row_destroy;
pspec = g_param_spec_boolean ("selected", NULL, NULL,
- FALSE, G_PARAM_READWRITE);
+ FALSE, G_PARAM_READWRITE);
g_object_class_install_property (object_class, PROP_SELECTED, pspec);
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/Software/gs-app-addon-row.ui");
@@ -273,7 +267,7 @@ gs_app_addon_row_init (GsAppAddonRow *row)
gtk_widget_init_template (GTK_WIDGET (row));
g_signal_connect (priv->checkbox, "toggled",
- G_CALLBACK (checkbox_toggled), row);
+ G_CALLBACK (checkbox_toggled), row);
}
void
diff --git a/src/gs-app-folder-dialog.c b/src/gs-app-folder-dialog.c
index aa90928..88b349f 100644
--- a/src/gs-app-folder-dialog.c
+++ b/src/gs-app-folder-dialog.c
@@ -24,10 +24,11 @@
#include <glib/gi18n.h>
#include <gtk/gtk.h>
+#include "gs-cleanup.h"
#include "gs-folders.h"
#include "gs-app-folder-dialog.h"
-typedef struct _GsAppFolderDialogPrivate GsAppFolderDialogPrivate;
+typedef struct _GsAppFolderDialogPrivate GsAppFolderDialogPrivate;
struct _GsAppFolderDialogPrivate
{
GList *apps;
@@ -39,8 +40,8 @@ struct _GsAppFolderDialogPrivate
GtkSizeGroup *rows;
GtkSizeGroup *labels;
GtkListBoxRow *new_folder_button;
- GtkWidget *new_folder_popover;
- GtkWidget *new_folder_entry;
+ GtkWidget *new_folder_popover;
+ GtkWidget *new_folder_entry;
GtkListBoxRow *selected_row;
};
@@ -114,8 +115,8 @@ new_folder_cb (GsAppFolderDialog *dialog)
static void
update_header_func (GtkListBoxRow *row,
- GtkListBoxRow *before,
- gpointer user_data)
+ GtkListBoxRow *before,
+ gpointer user_data)
{
GtkWidget *current;
@@ -162,7 +163,7 @@ gs_app_folder_dialog_class_init (GsAppFolderDialogClass *klass)
gtk_widget_class_bind_template_child_private (widget_class, GsAppFolderDialog, header);
gtk_widget_class_bind_template_child_private (widget_class, GsAppFolderDialog, cancel_button);
gtk_widget_class_bind_template_child_private (widget_class, GsAppFolderDialog, done_button);
- gtk_widget_class_bind_template_child_private (widget_class, GsAppFolderDialog, app_folder_list);
+ gtk_widget_class_bind_template_child_private (widget_class, GsAppFolderDialog, app_folder_list);
}
static GtkWidget *
@@ -177,11 +178,11 @@ create_row (GsAppFolderDialog *dialog, const gchar *folder)
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
label = gtk_label_new (gs_folders_get_folder_name (priv->folders, folder));
g_object_set (label,
- "margin-start", 20,
- "margin-end", 20,
- "margin-top", 10,
- "margin-bottom", 10,
- NULL);
+ "margin-start", 20,
+ "margin-end", 20,
+ "margin-top", 10,
+ "margin-bottom", 10,
+ NULL);
gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
gtk_widget_set_valign (label, GTK_ALIGN_START);
gtk_container_add (GTK_CONTAINER (box), label);
@@ -215,15 +216,14 @@ static void
populate_list (GsAppFolderDialog *dialog)
{
GsAppFolderDialogPrivate *priv = PRIVATE (dialog);
- gchar **folders;
guint i;
+ _cleanup_free_ gchar **folders = NULL;
folders = gs_folders_get_nonempty_folders (priv->folders);
for (i = 0; folders[i]; i++) {
gtk_list_box_insert (GTK_LIST_BOX (priv->app_folder_list),
- create_row (dialog, folders[i]), -1);
+ create_row (dialog, folders[i]), -1);
}
- g_free (folders);
}
static void
@@ -292,8 +292,8 @@ add_folder_add (GtkButton *button, GsAppFolderDialog *dialog)
row,
gtk_list_box_row_get_index (priv->new_folder_button));
select_row (GTK_LIST_BOX (priv->app_folder_list),
- GTK_LIST_BOX_ROW (row),
- dialog);
+ GTK_LIST_BOX_ROW (row),
+ dialog);
}
}
@@ -309,8 +309,8 @@ static void
create_folder_name_popover (GsAppFolderDialog *dialog)
{
GsAppFolderDialogPrivate *priv = PRIVATE (dialog);
- gchar *title;
GtkWidget *grid, *label, *button;
+ _cleanup_free_ gchar *title = NULL;
priv->new_folder_popover = gtk_popover_new (GTK_WIDGET (priv->new_folder_button));
gtk_popover_set_position (GTK_POPOVER (priv->new_folder_popover), GTK_POS_TOP);
@@ -324,7 +324,6 @@ create_folder_name_popover (GsAppFolderDialog *dialog)
title = g_strdup_printf ("<b>%s</b>", _("Folder Name"));
label = gtk_label_new (title);
- g_free (title);
gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
gtk_widget_set_halign (label, GTK_ALIGN_CENTER);
gtk_grid_attach (GTK_GRID (grid), label, 0, 0, 2, 1);
@@ -385,7 +384,7 @@ gs_app_folder_dialog_new (GtkWindow *parent, GList *apps)
"transient-for", parent,
"modal", TRUE,
NULL);
- set_apps (dialog, apps);
+ set_apps (dialog, apps);
populate_list (dialog);
add_new_folder_row (dialog);
diff --git a/src/gs-app-row.c b/src/gs-app-row.c
index 4d607a4..ed06c8d 100644
--- a/src/gs-app-row.c
+++ b/src/gs-app-row.c
@@ -26,6 +26,7 @@
#include <gtk/gtk.h>
#include "gs-app-row.h"
+#include "gs-cleanup.h"
#include "gs-star-widget.h"
#include "gs-markdown.h"
#include "gs-utils.h"
@@ -75,24 +76,22 @@ static guint signals [SIGNAL_LAST] = { 0 };
static GString *
gs_app_row_get_description (GsAppRow *app_row)
{
- GString *str = NULL;
GsAppRowPrivate *priv = app_row->priv;
- GsMarkdown *markdown = NULL;
const gchar *tmp = NULL;
- gchar *escaped = NULL;
+ _cleanup_free_ gchar *escaped = NULL;
/* convert the markdown update description into PangoMarkup */
if (priv->show_update &&
gs_app_get_state (priv->app) == AS_APP_STATE_UPDATABLE) {
tmp = gs_app_get_update_details (priv->app);
if (tmp != NULL && tmp[0] != '\0') {
+ _cleanup_object_unref_ GsMarkdown *markdown = NULL;
markdown = gs_markdown_new (GS_MARKDOWN_OUTPUT_PANGO);
gs_markdown_set_smart_quoting (markdown, FALSE);
gs_markdown_set_autocode (markdown, FALSE);
gs_markdown_set_autolinkify (markdown, FALSE);
escaped = gs_markdown_parse (markdown, tmp);
- str = g_string_new (escaped);
- goto out;
+ return g_string_new (escaped);
}
}
@@ -106,12 +105,7 @@ gs_app_row_get_description (GsAppRow *app_row)
if (tmp == NULL || (tmp != NULL && tmp[0] == '\0'))
tmp = gs_app_get_name (priv->app);
escaped = g_markup_escape_text (tmp, -1);
- str = g_string_new (escaped);
-out:
- if (markdown != NULL)
- g_object_unref (markdown);
- g_free (escaped);
- return str;
+ return g_string_new (escaped);
}
/**
@@ -123,8 +117,6 @@ gs_app_row_refresh (GsAppRow *app_row)
GsAppRowPrivate *priv = app_row->priv;
GtkStyleContext *context;
GString *str = NULL;
- GsFolders *folders;
- const gchar *folder;
if (app_row->priv->app == NULL)
return;
@@ -163,13 +155,14 @@ gs_app_row_refresh (GsAppRow *app_row)
if (priv->show_update) {
gtk_widget_hide (priv->folder_label);
} else {
+ _cleanup_object_unref_ GsFolders *folders = NULL;
+ const gchar *folder;
folders = gs_folders_get ();
folder = gs_folders_get_app_folder (folders, gs_app_get_id (priv->app), gs_app_get_categories
(priv->app));
if (folder)
folder = gs_folders_get_folder_name (folders, folder);
gtk_label_set_label (GTK_LABEL (priv->folder_label), folder);
gtk_widget_set_visible (priv->folder_label, folder != NULL);
- g_object_unref (folders);
}
if (gs_app_get_pixbuf (priv->app))
@@ -321,8 +314,8 @@ gs_app_row_refresh_idle_cb (gpointer user_data)
**/
static void
gs_app_row_notify_props_changed_cb (GsApp *app,
- GParamSpec *pspec,
- GsAppRow *app_row)
+ GParamSpec *pspec,
+ GsAppRow *app_row)
{
GsAppRowPrivate *priv = app_row->priv;
if (priv->pending_refresh_id > 0)
@@ -374,13 +367,13 @@ gs_app_row_set_property (GObject *object, guint prop_id, const GValue *value, GP
{
GsAppRow *app_row = GS_APP_ROW (object);
- switch (prop_id) {
- case PROP_SELECTED:
+ switch (prop_id) {
+ case PROP_SELECTED:
gs_app_row_set_selected (app_row, g_value_get_boolean (value));
break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
}
}
@@ -389,12 +382,12 @@ gs_app_row_get_property (GObject *object, guint prop_id, GValue *value, GParamSp
{
GsAppRow *app_row = GS_APP_ROW (object);
- switch (prop_id) {
- case PROP_SELECTED:
+ switch (prop_id) {
+ case PROP_SELECTED:
g_value_set_boolean (value, gs_app_row_get_selected (app_row));
break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
@@ -478,8 +471,8 @@ gs_app_row_init (GsAppRow *app_row)
void
gs_app_row_set_size_groups (GsAppRow *app_row,
- GtkSizeGroup *image,
- GtkSizeGroup *name)
+ GtkSizeGroup *image,
+ GtkSizeGroup *name)
{
gtk_size_group_add_widget (image, app_row->priv->image);
gtk_size_group_add_widget (name, app_row->priv->name_box);
diff --git a/src/gs-app-tile.c b/src/gs-app-tile.c
index 3528c43..96d16bf 100644
--- a/src/gs-app-tile.c
+++ b/src/gs-app-tile.c
@@ -25,6 +25,7 @@
#include <gtk/gtk.h>
#include "gs-app-tile.h"
+#include "gs-cleanup.h"
#include "gs-star-widget.h"
#include "gs-utils.h"
@@ -60,10 +61,10 @@ app_state_changed_idle (gpointer user_data)
GsAppTilePrivate *priv;
GtkWidget *label;
gboolean installed;
- gchar *name;
+ _cleanup_free_ gchar *name = NULL;
- priv = gs_app_tile_get_instance_private (tile);
- accessible = gtk_widget_get_accessible (GTK_WIDGET (tile));
+ priv = gs_app_tile_get_instance_private (tile);
+ accessible = gtk_widget_get_accessible (GTK_WIDGET (tile));
label = gtk_bin_get_child (GTK_BIN (priv->eventbox));
switch (gs_app_get_state (priv->app)) {
@@ -104,13 +105,13 @@ app_state_changed_idle (gpointer user_data)
* application available */
gtk_label_set_label (GTK_LABEL (label), _("Updates"));
break;
- case AS_APP_STATE_QUEUED_FOR_INSTALL:
- case AS_APP_STATE_AVAILABLE:
- default:
+ case AS_APP_STATE_QUEUED_FOR_INSTALL:
+ case AS_APP_STATE_AVAILABLE:
+ default:
installed = FALSE;
name = g_strdup (gs_app_get_name (priv->app));
- break;
- }
+ break;
+ }
gtk_widget_set_visible (priv->eventbox, installed);
@@ -118,7 +119,6 @@ app_state_changed_idle (gpointer user_data)
atk_object_set_name (accessible, name);
atk_object_set_description (accessible, gs_app_get_summary (priv->app));
}
- g_free (name);
g_object_unref (tile);
return G_SOURCE_REMOVE;
@@ -163,9 +163,9 @@ gs_app_tile_set_app (GsAppTile *tile, GsApp *app)
gtk_stack_set_visible_child_name (GTK_STACK (priv->stack), "content");
- g_signal_connect (priv->app, "notify::state",
- G_CALLBACK (app_state_changed), tile);
- app_state_changed (priv->app, NULL, tile);
+ g_signal_connect (priv->app, "notify::state",
+ G_CALLBACK (app_state_changed), tile);
+ app_state_changed (priv->app, NULL, tile);
gs_image_set_from_pixbuf (GTK_IMAGE (priv->image), gs_app_get_pixbuf (app));
gtk_label_set_label (GTK_LABEL (priv->name), gs_app_get_name (app));
@@ -212,9 +212,9 @@ gs_app_tile_class_init (GsAppTileClass *klass)
gtk_widget_class_bind_template_child_private (widget_class, GsAppTile, image);
gtk_widget_class_bind_template_child_private (widget_class, GsAppTile, name);
gtk_widget_class_bind_template_child_private (widget_class, GsAppTile, summary);
- gtk_widget_class_bind_template_child_private (widget_class, GsAppTile, eventbox);
- gtk_widget_class_bind_template_child_private (widget_class, GsAppTile, stack);
- gtk_widget_class_bind_template_child_private (widget_class, GsAppTile, stars);
+ gtk_widget_class_bind_template_child_private (widget_class, GsAppTile, eventbox);
+ gtk_widget_class_bind_template_child_private (widget_class, GsAppTile, stack);
+ gtk_widget_class_bind_template_child_private (widget_class, GsAppTile, stars);
}
GtkWidget *
diff --git a/src/gs-app.c b/src/gs-app.c
index ca21192..10a1c67 100644
--- a/src/gs-app.c
+++ b/src/gs-app.c
@@ -47,6 +47,7 @@
#include <gtk/gtk.h>
#include "gs-app.h"
+#include "gs-cleanup.h"
#include "gs-utils.h"
static void gs_app_finalize (GObject *object);
@@ -320,7 +321,7 @@ notify_idle_cb (gpointer data)
AppNotifyData *notify_data = data;
g_object_notify (G_OBJECT (notify_data->app),
- notify_data->property_name);
+ notify_data->property_name);
g_object_unref (notify_data->app);
g_free (notify_data->property_name);
@@ -812,7 +813,7 @@ gs_app_set_icon (GsApp *app, AsIcon *icon)
}
static GtkIconTheme *icon_theme_singleton;
-static GMutex icon_theme_lock;
+static GMutex icon_theme_lock;
static GHashTable *icon_theme_paths;
/**
@@ -852,8 +853,7 @@ gboolean
gs_app_load_icon (GsApp *app, gint scale, GError **error)
{
AsIcon *icon;
- GdkPixbuf *pixbuf = NULL;
- gboolean ret = TRUE;
+ _cleanup_object_unref_ GdkPixbuf *pixbuf = NULL;
g_return_val_if_fail (GS_IS_APP (app), FALSE);
g_return_val_if_fail (app->priv->icon != NULL, FALSE);
@@ -894,15 +894,10 @@ gs_app_load_icon (GsApp *app, gint scale, GError **error)
as_icon_kind_to_string (as_icon_get_kind (icon)));
break;
}
- if (pixbuf == NULL) {
- ret = FALSE;
- goto out;
- }
+ if (pixbuf == NULL)
+ return FALSE;
gs_app_set_pixbuf (app, pixbuf);
-out:
- if (pixbuf != NULL)
- g_object_unref (pixbuf);
- return ret;
+ return TRUE;
}
/**
@@ -2072,9 +2067,9 @@ gs_app_init (GsApp *app)
g_free,
g_free);
app->priv->addons_hash = g_hash_table_new_full (g_str_hash,
- g_str_equal,
- g_free,
- NULL);
+ g_str_equal,
+ g_free,
+ NULL);
app->priv->related_hash = g_hash_table_new_full (g_str_hash,
g_str_equal,
g_free,
diff --git a/src/gs-application.c b/src/gs-application.c
index 4e069ea..b2077fd 100644
--- a/src/gs-application.c
+++ b/src/gs-application.c
@@ -32,6 +32,7 @@
#include "gs-dbus-helper.h"
#include "gs-box.h"
+#include "gs-cleanup.h"
#include "gs-first-run-dialog.h"
#include "gs-shell.h"
#include "gs-update-monitor.h"
@@ -88,8 +89,8 @@ gs_application_init (GsApplication *application)
static void
download_updates_setting_changed (GSettings *settings,
- const gchar *key,
- GsApplication *app)
+ const gchar *key,
+ GsApplication *app)
{
if (g_settings_get_boolean (settings, key)) {
g_debug ("Enabling update monitor");
@@ -104,10 +105,10 @@ static void
gs_application_monitor_updates (GsApplication *app)
{
g_signal_connect (app->settings, "changed::download-updates",
- G_CALLBACK (download_updates_setting_changed), app);
+ G_CALLBACK (download_updates_setting_changed), app);
download_updates_setting_changed (app->settings,
- "download-updates",
- app);
+ "download-updates",
+ app);
}
static void
@@ -135,7 +136,7 @@ static void
gs_application_initialize_plugins (GsApplication *app)
{
static gboolean initialized = FALSE;
- GError *error = NULL;
+ _cleanup_error_free_ GError *error = NULL;
if (initialized)
return;
@@ -181,8 +182,8 @@ static void
gs_application_initialize_ui (GsApplication *app)
{
static gboolean initialized = FALSE;
- GFile *file;
gchar *theme;
+ _cleanup_object_unref_ GFile *file = NULL;
if (initialized)
return;
@@ -204,7 +205,6 @@ gs_application_initialize_ui (GsApplication *app)
file = g_file_new_for_uri ("resource:///org/gnome/Software/gtk-style.css");
}
gtk_css_provider_load_from_file (app->provider, file, NULL);
- g_object_unref (file);
gs_application_initialize_plugins (app);
@@ -243,9 +243,9 @@ about_activated (GSimpleAction *action,
};
const gchar *copyright = "Copyright \xc2\xa9 2013 Richard Hughes, Matthias Clasen";
GtkIconTheme *icon_theme;
- GdkPixbuf *logo;
GList *windows;
GtkWindow *parent = NULL;
+ _cleanup_object_unref_ GdkPixbuf *logo = NULL;
gs_application_initialize_ui (app);
@@ -270,8 +270,6 @@ about_activated (GSimpleAction *action,
"translator-credits", _("translator-credits"),
"version", VERSION,
NULL);
-
- g_object_unref (logo);
}
static void
@@ -406,9 +404,9 @@ launch_activated (GSimpleAction *action,
{
const gchar *desktop_id;
GdkDisplay *display;
- GAppInfo *appinfo;
- GAppLaunchContext *context;
- GError *error = NULL;
+ _cleanup_error_free_ GError *error = NULL;
+ _cleanup_object_unref_ GAppInfo *appinfo = NULL;
+ _cleanup_object_unref_ GAppLaunchContext *context = NULL;
desktop_id = g_variant_get_string (parameter, NULL);
display = gdk_display_get_default ();
@@ -421,11 +419,7 @@ launch_activated (GSimpleAction *action,
context = G_APP_LAUNCH_CONTEXT (gdk_display_get_app_launch_context (display));
if (!g_app_info_launch (appinfo, NULL, context, &error)) {
g_warning ("launching %s failed: %s", desktop_id, error->message);
- g_error_free (error);
}
-
- g_object_unref (appinfo);
- g_object_unref (context);
}
static void
@@ -433,11 +427,10 @@ clear_offline_updates (GSimpleAction *action,
GVariant *parameter,
gpointer data)
{
- GError *error = NULL;
+ _cleanup_error_free_ GError *error = NULL;
if (!pk_offline_clear_results (NULL, &error)) {
g_warning ("Failure clearing offline update message: %s",
error->message);
- g_error_free (error);
}
}
@@ -459,8 +452,8 @@ static GActionEntry actions[] = {
{ "details", details_activated, "(ss)", NULL, NULL },
{ "filename", filename_activated, "(s)", NULL, NULL },
{ "launch", launch_activated, "s", NULL, NULL },
- { "clear-offline-updates", clear_offline_updates, NULL, NULL, NULL },
- { "show-offline-update-error", show_offline_updates_error, NULL, NULL, NULL },
+ { "clear-offline-updates", clear_offline_updates, NULL, NULL, NULL },
+ { "show-offline-update-error", show_offline_updates_error, NULL, NULL, NULL },
{ "nop", NULL, NULL, NULL }
};
@@ -521,10 +514,9 @@ static gboolean
gs_application_local_command_line (GApplication *app, gchar ***args, gint *status)
{
GOptionContext *context;
- gboolean gapplication_service = FALSE;
+ gboolean gapplication_service = FALSE;
gchar *mode = NULL;
gchar *search = NULL;
- gchar *local_filename = NULL;
gchar *id = NULL;
gboolean activate_ui = TRUE;
gboolean prefer_local = FALSE;
@@ -532,9 +524,10 @@ gs_application_local_command_line (GApplication *app, gchar ***args, gint *statu
gboolean profile = FALSE;
gboolean verbose = FALSE;
gint argc;
+ _cleanup_free_ gchar *local_filename = NULL;
const GOptionEntry options[] = {
- { "gapplication-service", '\0', 0, G_OPTION_ARG_NONE, &gapplication_service,
- _("Enter GApplication service mode"), NULL },
+ { "gapplication-service", '\0', 0, G_OPTION_ARG_NONE, &gapplication_service,
+ _("Enter GApplication service mode"), NULL },
{ "mode", '\0', 0, G_OPTION_ARG_STRING, &mode,
/* TRANSLATORS: this is a command line option */
_("Start up mode: either ‘updates’, ‘updated’, ‘installed’ or ‘overview’"), _("MODE") },
@@ -553,7 +546,7 @@ gs_application_local_command_line (GApplication *app, gchar ***args, gint *statu
{ "version", 0, 0, G_OPTION_ARG_NONE, &version, NULL, NULL },
{ NULL}
};
- GError *error = NULL;
+ _cleanup_error_free_ GError *error = NULL;
context = g_option_context_new ("");
g_option_context_add_main_entries (context, options, NULL);
@@ -561,7 +554,6 @@ gs_application_local_command_line (GApplication *app, gchar ***args, gint *statu
argc = g_strv_length (*args);
if (!g_option_context_parse (context, &argc, args, &error)) {
g_printerr ("%s\n", error->message);
- g_error_free (error);
*status = 1;
goto out;
}
@@ -589,7 +581,6 @@ gs_application_local_command_line (GApplication *app, gchar ***args, gint *statu
if (!g_application_register (app, NULL, &error)) {
g_printerr ("%s\n", error->message);
- g_error_free (error);
*status = 1;
goto out;
}
@@ -625,7 +616,6 @@ gs_application_local_command_line (GApplication *app, gchar ***args, gint *statu
out:
g_option_context_free (context);
- g_free (local_filename);
return TRUE;
}
diff --git a/src/gs-box.c b/src/gs-box.c
index 878aaef..bb497c7 100644
--- a/src/gs-box.c
+++ b/src/gs-box.c
@@ -25,6 +25,7 @@
#include <gtk/gtk.h>
#include "gs-box.h"
+#include "gs-cleanup.h"
typedef struct {
GtkWidget *widget;
@@ -128,11 +129,12 @@ gs_box_get_preferred_width (GtkWidget *widget, gint *min, gint *nat)
{
GsBox *box = GS_BOX (widget);
GsBoxChild *child;
- gint cm, *cn;
+ gint cm;
gint n_children;
gint ms, m, n;
GList *l;
gint i;
+ _cleanup_free_ gint *cn = NULL;
n_children = g_list_length (box->children);
@@ -152,8 +154,6 @@ gs_box_get_preferred_width (GtkWidget *widget, gint *min, gint *nat)
n += MAX (cn[i], cm);
}
- g_free (cn);
-
if (min)
*min = m;
if (nat)
diff --git a/src/gs-cmd.c b/src/gs-cmd.c
index 047fac3..c810d21 100644
--- a/src/gs-cmd.c
+++ b/src/gs-cmd.c
@@ -25,6 +25,7 @@
#include <gtk/gtk.h>
#include <locale.h>
+#include "gs-cleanup.h"
#include "gs-profile.h"
#include "gs-plugin-loader.h"
#include "gs-plugin-loader-sync.h"
@@ -39,20 +40,19 @@ gs_cmd_show_results_apps (GList *list)
GPtrArray *related;
GsApp *app;
GsApp *app_rel;
- gchar *tmp;
guint i;
for (l = list; l != NULL; l = l->next) {
+ _cleanup_free_ gchar *tmp = NULL;
app = GS_APP (l->data);
tmp = gs_app_to_string (app);
g_print ("%s\n", tmp);
- g_free (tmp);
related = gs_app_get_related (app);
for (i = 0; i < related->len; i++) {
+ _cleanup_free_ gchar *tmp_rel = NULL;
app_rel = GS_APP (g_ptr_array_index (related, i));
- tmp = gs_app_to_string (app_rel);
- g_print ("\t%s\n", tmp);
- g_free (tmp);
+ tmp_rel = gs_app_to_string (app_rel);
+ g_print ("\t%s\n", tmp_rel);
}
}
}
@@ -82,20 +82,19 @@ gs_cmd_show_results_categories (GList *list)
GList *subcats;
GsCategory *cat;
GsCategory *parent;
- gchar *id;
- gchar *tmp;
for (l = list; l != NULL; l = l->next) {
+ _cleanup_free_ gchar *tmp = NULL;
cat = GS_CATEGORY (l->data);
parent = gs_category_get_parent (cat);
if (parent != NULL){
+ _cleanup_free_ gchar *id = NULL;
id = g_strdup_printf ("%s/%s",
gs_category_get_id (parent),
gs_category_get_id (cat));
tmp = gs_cmd_pad_spaces (id, 32);
g_print ("%s : %s\n",
tmp, gs_category_get_name (cat));
- g_free (id);
} else {
tmp = gs_cmd_pad_spaces (gs_category_get_id (cat), 32);
g_print ("%s : %s\n",
@@ -103,7 +102,6 @@ gs_cmd_show_results_categories (GList *list)
subcats = gs_category_get_subcategories (cat);
gs_cmd_show_results_categories (subcats);
}
- g_free (tmp);
}
}
@@ -153,48 +151,41 @@ static guint64
gs_cmd_parse_refine_flags (const gchar *extra, GError **error)
{
GsPluginRefineFlags tmp;
- gchar **split = NULL;
guint i;
guint64 refine_flags = GS_PLUGIN_REFINE_FLAGS_DEFAULT;
+ _cleanup_strv_free_ gchar **split = NULL;
if (extra == NULL)
- goto out;
+ return GS_PLUGIN_REFINE_FLAGS_DEFAULT;
split = g_strsplit (extra, ",", -1);
for (i = 0; split[i] != NULL; i++) {
tmp = gs_cmd_refine_flag_from_string (split[i], error);
- if (tmp == 0) {
- refine_flags = G_MAXUINT64;
- goto out;
- }
+ if (tmp == 0)
+ return G_MAXUINT64;
refine_flags |= tmp;
}
-out:
- g_strfreev (split);
return refine_flags;
}
int
main (int argc, char **argv)
{
- GError *error = NULL;
GList *list = NULL;
GList *categories = NULL;
GOptionContext *context;
- GsApp *app = NULL;
- GsCategory *parent = NULL;
- GsCategory *category = NULL;
- GsPluginLoader *plugin_loader = NULL;
- GsProfile *profile = NULL;
gboolean prefer_local = FALSE;
gboolean ret;
gboolean show_results = FALSE;
guint64 refine_flags = GS_PLUGIN_REFINE_FLAGS_DEFAULT;
- gchar *refine_flags_str = NULL;
- gchar **split = NULL;
gint i;
gint repeat = 1;
int status = 0;
+ _cleanup_error_free_ GError *error = NULL;
+ _cleanup_free_ gchar *refine_flags_str = NULL;
+ _cleanup_object_unref_ GsApp *app = NULL;
+ _cleanup_object_unref_ GsPluginLoader *plugin_loader = NULL;
+ _cleanup_object_unref_ GsProfile *profile = NULL;
const GOptionEntry options[] = {
{ "show-results", '\0', 0, G_OPTION_ARG_NONE, &show_results,
"Show the results for the action", NULL },
@@ -223,7 +214,6 @@ main (int argc, char **argv)
ret = g_option_context_parse (context, &argc, &argv, &error);
if (!ret) {
g_print ("Failed to parse options: %s\n", error->message);
- g_error_free (error);
goto out;
}
@@ -235,7 +225,6 @@ main (int argc, char **argv)
refine_flags = gs_cmd_parse_refine_flags (refine_flags_str, &error);
if (refine_flags == G_MAXUINT64) {
g_print ("Flag unknown: %s\n", error->message);
- g_error_free (error);
goto out;
}
@@ -248,7 +237,6 @@ main (int argc, char **argv)
ret = gs_plugin_loader_setup (plugin_loader, &error);
if (!ret) {
g_print ("Failed to setup plugins: %s\n", error->message);
- g_error_free (error);
goto out;
}
gs_plugin_loader_dump_state (plugin_loader);
@@ -365,13 +353,15 @@ main (int argc, char **argv)
}
}
} else if (argc == 3 && g_strcmp0 (argv[1], "get-category-apps") == 0) {
+ _cleanup_object_unref_ GsCategory *category = NULL;
+ _cleanup_strv_free_ gchar **split = NULL;
split = g_strsplit (argv[2], "/", 2);
if (g_strv_length (split) == 1) {
category = gs_category_new (NULL, split[0], NULL);
} else {
+ _cleanup_object_unref_ GsCategory *parent = NULL;
parent = gs_category_new (NULL, split[0], NULL);
category = gs_category_new (parent, split[1], NULL);
- g_object_unref (parent);
}
for (i = 0; i < repeat; i++) {
if (list != NULL)
@@ -398,7 +388,6 @@ main (int argc, char **argv)
}
if (!ret) {
g_print ("Failed: %s\n", error->message);
- g_error_free (error);
goto out;
}
@@ -410,17 +399,7 @@ out:
gs_profile_stop (profile, "GsCmd");
gs_profile_dump (profile);
g_option_context_free (context);
- g_free (refine_flags_str);
- g_strfreev (split);
gs_plugin_list_free (list);
- if (app != NULL)
- g_object_unref (app);
- if (category != NULL)
- g_object_unref (category);
- if (plugin_loader != NULL)
- g_object_unref (plugin_loader);
- if (profile != NULL)
- g_object_unref (profile);
return status;
}
diff --git a/src/gs-dbus-helper.c b/src/gs-dbus-helper.c
index 01e87a3..69252ac 100644
--- a/src/gs-dbus-helper.c
+++ b/src/gs-dbus-helper.c
@@ -25,6 +25,7 @@
#include <gtk/gtk.h>
#include <packagekit-glib2/packagekit.h>
+#include "gs-cleanup.h"
#include "gs-dbus-helper.h"
#include "gs-resources.h"
@@ -67,8 +68,8 @@ gs_dbus_helper_task_free (GsDbusHelperTask *dtask)
static void
gs_dbus_helper_task_set_interaction (GsDbusHelperTask *dtask, const gchar *interaction)
{
- gchar **interactions;
guint i;
+ _cleanup_strv_free_ gchar **interactions = NULL;
interactions = g_strsplit (interaction, ",", -1);
for (i = 0; interactions[i] != NULL; i++) {
@@ -97,7 +98,6 @@ gs_dbus_helper_task_set_interaction (GsDbusHelperTask *dtask, const gchar *inter
else if (g_strcmp0 (interactions[i], "hide-confirm-deps") == 0)
dtask->show_confirm_deps = FALSE;
}
- g_strfreev (interactions);
}
/**
@@ -114,12 +114,12 @@ gs_dbus_helper_progress_cb (PkProgress *progress, PkProgressType type, gpointer
static void
gs_dbus_helper_query_is_installed_cb (GObject *source, GAsyncResult *res, gpointer data)
{
- GError *error = NULL;
- GPtrArray *array = NULL;
GsDbusHelperTask *dtask = (GsDbusHelperTask *) data;
PkClient *client = PK_CLIENT (source);
- PkError *error_code = NULL;
- PkResults *results = NULL;
+ _cleanup_error_free_ GError *error = NULL;
+ _cleanup_object_unref_ PkError *error_code = NULL;
+ _cleanup_object_unref_ PkResults *results = NULL;
+ _cleanup_ptrarray_unref_ GPtrArray *array = NULL;
/* get the results */
results = pk_client_generic_finish (client, res, &error);
@@ -129,7 +129,6 @@ gs_dbus_helper_query_is_installed_cb (GObject *source, GAsyncResult *res, gpoint
G_IO_ERROR_INVALID_ARGUMENT,
"failed to resolve: %s",
error->message);
- g_error_free (error);
goto out;
}
@@ -150,12 +149,6 @@ gs_dbus_helper_query_is_installed_cb (GObject *source, GAsyncResult *res, gpoint
g_variant_new ("(b)", array->len > 0));
out:
gs_dbus_helper_task_free (dtask);
- if (error_code != NULL)
- g_object_unref (error_code);
- if (array != NULL)
- g_ptr_array_unref (array);
- if (results != NULL)
- g_object_unref (results);
}
/**
@@ -164,14 +157,14 @@ out:
static void
gs_dbus_helper_query_search_file_cb (GObject *source, GAsyncResult *res, gpointer data)
{
- GError *error = NULL;
- GPtrArray *array = NULL;
+ _cleanup_error_free_ GError *error = NULL;
GsDbusHelperTask *dtask = (GsDbusHelperTask *) data;
PkClient *client = PK_CLIENT (source);
- PkError *error_code = NULL;
PkInfoEnum info;
PkPackage *item;
- PkResults *results = NULL;
+ _cleanup_ptrarray_unref_ GPtrArray *array = NULL;
+ _cleanup_object_unref_ PkError *error_code = NULL;
+ _cleanup_object_unref_ PkResults *results = NULL;
/* get the results */
results = pk_client_generic_finish (client, res, &error);
@@ -181,8 +174,7 @@ gs_dbus_helper_query_search_file_cb (GObject *source, GAsyncResult *res, gpointe
G_IO_ERROR_INVALID_ARGUMENT,
"failed to search: %s",
error->message);
- g_error_free (error);
- goto out;
+ return;
}
/* check error code */
@@ -193,7 +185,7 @@ gs_dbus_helper_query_search_file_cb (GObject *source, GAsyncResult *res, gpointe
G_IO_ERROR_INVALID_ARGUMENT,
"failed to search: %s",
pk_error_get_details (error_code));
- goto out;
+ return;
}
/* get results */
@@ -204,7 +196,7 @@ gs_dbus_helper_query_search_file_cb (GObject *source, GAsyncResult *res, gpointe
G_IO_ERROR,
G_IO_ERROR_INVALID_ARGUMENT,
"failed to find any packages");
- goto out;
+ return;
}
/* get first item */
@@ -214,13 +206,6 @@ gs_dbus_helper_query_search_file_cb (GObject *source, GAsyncResult *res, gpointe
g_variant_new ("(bs)",
info == PK_INFO_ENUM_INSTALLED,
pk_package_get_name (item)));
-out:
- if (error_code != NULL)
- g_object_unref (error_code);
- if (array != NULL)
- g_ptr_array_unref (array);
- if (results != NULL)
- g_object_unref (results);
}
static void
@@ -229,7 +214,7 @@ gs_dbus_helper_handle_method_call_query (GsDbusHelper *dbus_helper,
GVariant *parameters,
GDBusMethodInvocation *invocation)
{
- gchar **names;
+ _cleanup_strv_free_ gchar **names = NULL;
const gchar *name;
const gchar *interaction;
GsDbusHelperTask *dtask;
@@ -246,7 +231,6 @@ gs_dbus_helper_handle_method_call_query (GsDbusHelper *dbus_helper,
names, NULL,
gs_dbus_helper_progress_cb, dtask,
gs_dbus_helper_query_is_installed_cb, dtask);
- g_strfreev (names);
} else if (g_strcmp0 (method_name, "SearchFile") == 0) {
g_variant_get (parameters, "(&s&s)",
&name, &interaction);
@@ -259,7 +243,6 @@ gs_dbus_helper_handle_method_call_query (GsDbusHelper *dbus_helper,
names, NULL,
gs_dbus_helper_progress_cb, dtask,
gs_dbus_helper_query_search_file_cb, dtask);
- g_strfreev (names);
} else {
g_dbus_method_invocation_return_error (invocation,
G_IO_ERROR,
@@ -359,7 +342,7 @@ gs_dbus_helper_name_lost_cb (GDBusConnection *connection,
static void
gs_dbus_helper_init (GsDbusHelper *dbus_helper)
{
- GBytes *data;
+ _cleanup_bytes_unref_ GBytes *data = NULL;
const gchar *xml;
dbus_helper->task = pk_task_new ();
@@ -373,7 +356,6 @@ gs_dbus_helper_init (GsDbusHelper *dbus_helper)
xml = g_bytes_get_data (data, NULL);
dbus_helper->introspection = g_dbus_node_info_new_for_xml (xml, NULL);
g_assert (dbus_helper->introspection != NULL);
- g_bytes_unref (data);
/* own session daemon */
dbus_helper->owner_id = g_bus_own_name (G_BUS_TYPE_SESSION,
diff --git a/src/gs-feature-tile.c b/src/gs-feature-tile.c
index 6ad45e6..8c83983 100644
--- a/src/gs-feature-tile.c
+++ b/src/gs-feature-tile.c
@@ -24,6 +24,7 @@
#include <glib/gi18n.h>
#include <gtk/gtk.h>
+#include "gs-cleanup.h"
#include "gs-feature-tile.h"
struct _GsFeatureTilePrivate
@@ -52,41 +53,40 @@ gs_feature_tile_get_app (GsFeatureTile *tile)
static gboolean
app_state_changed_idle (gpointer user_data)
{
- GsFeatureTile *tile = GS_FEATURE_TILE (user_data);
- GsFeatureTilePrivate *priv;
- AtkObject *accessible;
- gchar *name;
-
- priv = gs_feature_tile_get_instance_private (tile);
- accessible = gtk_widget_get_accessible (GTK_WIDGET (tile));
-
- switch (gs_app_get_state (priv->app)) {
- case AS_APP_STATE_INSTALLED:
- case AS_APP_STATE_INSTALLING:
- case AS_APP_STATE_REMOVING:
- name = g_strdup_printf ("%s (%s)",
- gs_app_get_name (priv->app),
- _("Installed"));
- break;
- case AS_APP_STATE_UPDATABLE:
- name = g_strdup_printf ("%s (%s)",
- gs_app_get_name (priv->app),
- _("Updates"));
- break;
- case AS_APP_STATE_AVAILABLE:
- default:
- name = g_strdup (gs_app_get_name (priv->app));
- break;
- }
-
- if (GTK_IS_ACCESSIBLE (accessible)) {
- atk_object_set_name (accessible, name);
- atk_object_set_description (accessible, gs_app_get_summary (priv->app));
- }
- g_free (name);
-
- g_object_unref (tile);
- return G_SOURCE_REMOVE;
+ GsFeatureTile *tile = GS_FEATURE_TILE (user_data);
+ GsFeatureTilePrivate *priv;
+ AtkObject *accessible;
+ _cleanup_free_ gchar *name = NULL;
+
+ priv = gs_feature_tile_get_instance_private (tile);
+ accessible = gtk_widget_get_accessible (GTK_WIDGET (tile));
+
+ switch (gs_app_get_state (priv->app)) {
+ case AS_APP_STATE_INSTALLED:
+ case AS_APP_STATE_INSTALLING:
+ case AS_APP_STATE_REMOVING:
+ name = g_strdup_printf ("%s (%s)",
+ gs_app_get_name (priv->app),
+ _("Installed"));
+ break;
+ case AS_APP_STATE_UPDATABLE:
+ name = g_strdup_printf ("%s (%s)",
+ gs_app_get_name (priv->app),
+ _("Updates"));
+ break;
+ case AS_APP_STATE_AVAILABLE:
+ default:
+ name = g_strdup (gs_app_get_name (priv->app));
+ break;
+ }
+
+ if (GTK_IS_ACCESSIBLE (accessible)) {
+ atk_object_set_name (accessible, name);
+ atk_object_set_description (accessible, gs_app_get_summary (priv->app));
+ }
+
+ g_object_unref (tile);
+ return G_SOURCE_REMOVE;
}
static void
@@ -99,12 +99,11 @@ void
gs_feature_tile_set_app (GsFeatureTile *tile, GsApp *app)
{
GsFeatureTilePrivate *priv;
- GString *data = NULL;
const gchar *background;
const gchar *stroke_color;
const gchar *text_color;
const gchar *text_shadow;
- gchar *tmp;
+ _cleanup_string_free_ GString *data = NULL;
g_return_if_fail (GS_IS_FEATURE_TILE (tile));
g_return_if_fail (GS_IS_APP (app) || app == NULL);
@@ -122,9 +121,9 @@ gs_feature_tile_set_app (GsFeatureTile *tile, GsApp *app)
gtk_stack_set_visible_child_name (GTK_STACK (priv->stack), "content");
- g_signal_connect (priv->app, "notify::state",
- G_CALLBACK (app_state_changed), tile);
- app_state_changed (priv->app, NULL, tile);
+ g_signal_connect (priv->app, "notify::state",
+ G_CALLBACK (app_state_changed), tile);
+ app_state_changed (priv->app, NULL, tile);
gtk_label_set_label (GTK_LABEL (priv->title), gs_app_get_name (app));
gtk_label_set_label (GTK_LABEL (priv->subtitle), gs_app_get_summary (app));
@@ -132,11 +131,11 @@ gs_feature_tile_set_app (GsFeatureTile *tile, GsApp *app)
/* check the app has the featured data */
text_color = gs_app_get_metadata_item (app, "Featured::text-color");
if (text_color == NULL) {
+ _cleanup_free_ gchar *tmp = NULL;
tmp = gs_app_to_string (app);
g_warning ("%s has no featured data: %s",
gs_app_get_id (app), tmp);
- g_free (tmp);
- goto out;
+ return;
}
background = gs_app_get_metadata_item (app, "Featured::background");
stroke_color = gs_app_get_metadata_item (app, "Featured::stroke-color");
@@ -156,15 +155,12 @@ gs_feature_tile_set_app (GsFeatureTile *tile, GsApp *app)
g_string_append (data, "}\n");
g_string_append (data, ".button.featured-tile:hover {\n");
g_string_append (data, " background: linear-gradient(to bottom,\n");
- g_string_append (data, " alpha(#fff,0.16),\n");
+ g_string_append (data, " alpha(#fff,0.16),\n");
g_string_append_printf (data,
- " alpha(#aaa,0.16)), %s;\n",
+ " alpha(#aaa,0.16)), %s;\n",
background);
g_string_append (data, "}\n");
gtk_css_provider_load_from_data (priv->provider, data->str, -1, NULL);
-out:
- if (data != NULL)
- g_string_free (data, TRUE);
}
static void
diff --git a/src/gs-first-run-dialog.c b/src/gs-first-run-dialog.c
index 3241dd6..e92f5e2 100644
--- a/src/gs-first-run-dialog.c
+++ b/src/gs-first-run-dialog.c
@@ -67,8 +67,8 @@ GtkWidget *
gs_first_run_dialog_new (void)
{
return GTK_WIDGET (g_object_new (GS_TYPE_FIRST_RUN_DIALOG,
- "use-header-bar", TRUE,
- NULL));
+ "use-header-bar", TRUE,
+ NULL));
}
/* vim: set noexpandtab: */
diff --git a/src/gs-folders.c b/src/gs-folders.c
index 0f7365a..0a15c90 100644
--- a/src/gs-folders.c
+++ b/src/gs-folders.c
@@ -25,6 +25,7 @@
#include <glib/gi18n.h>
#include <gio/gio.h>
+#include "gs-cleanup.h"
#include "gs-folders.h"
#define APP_FOLDER_SCHEMA "org.gnome.desktop.app-folders"
@@ -123,18 +124,14 @@ static gchar *
lookup_folder_name (const gchar *id)
{
gchar *name = NULL;
- GKeyFile *key_file;
- gchar *file;
+ _cleanup_free_ gchar *file = NULL;
+ _cleanup_keyfile_unref_ GKeyFile *key_file = NULL;
file = g_build_filename ("desktop-directories", id, NULL);
key_file = g_key_file_new ();
if (g_key_file_load_from_data_dirs (key_file, file, NULL, G_KEY_FILE_NONE, NULL)) {
name = g_key_file_get_locale_string (key_file, "Desktop Entry", "Name", NULL, NULL);
}
-
- g_free (file);
- g_key_file_unref (key_file);
-
return name;
}
@@ -180,30 +177,31 @@ static void
load (GsFolders *folders)
{
GsFolder *folder;
- gchar **ids;
- gchar **apps;
- gchar **excluded_apps;
- gchar **categories;
guint i, j;
- gchar *name;
- gchar *path;
- gchar *child_path;
- GSettings *settings;
+ gchar *path;
gboolean translate;
GHashTableIter iter;
gchar *app;
gchar *category;
+ _cleanup_strv_free_ gchar **ids = NULL;
folders->priv->folders = g_hash_table_new_full (g_str_hash, g_str_equal, NULL,
(GDestroyNotify)gs_folder_free);
folders->priv->apps = g_hash_table_new (g_str_hash, g_str_equal);
folders->priv->categories = g_hash_table_new (g_str_hash, g_str_equal);
ids = g_settings_get_strv (folders->priv->settings, "folder-children");
- g_object_get (folders->priv->settings, "path", &path, NULL);
+ g_object_get (folders->priv->settings, "path", &path, NULL);
for (i = 0; ids[i]; i++) {
- child_path = g_strconcat (path, "folders/", ids[i], "/", NULL);
- settings = g_settings_new_with_path (APP_FOLDER_CHILD_SCHEMA, child_path);
- name = g_settings_get_string (settings, "name");
+ _cleanup_free_ gchar **apps = NULL;
+ _cleanup_free_ gchar **categories = NULL;
+ _cleanup_free_ gchar *child_path = NULL;
+ _cleanup_free_ gchar **excluded_apps = NULL;
+ _cleanup_free_ gchar *name = NULL;
+ _cleanup_object_unref_ GSettings *settings = NULL;
+
+ child_path = g_strconcat (path, "folders/", ids[i], "/", NULL);
+ settings = g_settings_new_with_path (APP_FOLDER_CHILD_SCHEMA, child_path);
+ name = g_settings_get_string (settings, "name");
translate = g_settings_get_boolean (settings, "translate");
folder = gs_folder_new (ids[i], name, translate);
@@ -233,15 +231,7 @@ load (GsFolders *folders)
while (g_hash_table_iter_next (&iter, (gpointer*)&category, NULL)) {
g_hash_table_insert (folders->priv->categories, category, folder);
}
-
- g_free (apps);
- g_free (excluded_apps);
- g_free (categories);
- g_free (name);
- g_object_unref (settings);
- g_free (child_path);
}
- g_strfreev (ids);
}
static void
@@ -249,17 +239,18 @@ save (GsFolders *folders)
{
GHashTableIter iter;
GsFolder *folder;
- gpointer apps;
- gchar *path;
- gchar *child_path;
- GSettings *settings;
gpointer keys;
+ _cleanup_free_ gchar *path = NULL;
+ _cleanup_free_ gpointer apps = NULL;
- g_object_get (folders->priv->settings, "path", &path, NULL);
+ g_object_get (folders->priv->settings, "path", &path, NULL);
g_hash_table_iter_init (&iter, folders->priv->folders);
while (g_hash_table_iter_next (&iter, NULL, (gpointer *)&folder)) {
- child_path = g_strconcat (path, "folders/", folder->id, "/", NULL);
- settings = g_settings_new_with_path (APP_FOLDER_CHILD_SCHEMA, child_path);
+ _cleanup_free_ gchar *child_path = NULL;
+ _cleanup_object_unref_ GSettings *settings = NULL;
+
+ child_path = g_strconcat (path, "folders/", folder->id, "/", NULL);
+ settings = g_settings_new_with_path (APP_FOLDER_CHILD_SCHEMA, child_path);
g_settings_set_string (settings, "name", folder->name);
g_settings_set_boolean (settings, "translate", folder->translate);
keys = g_hash_table_get_keys_as_array (folder->apps, NULL);
@@ -273,16 +264,11 @@ save (GsFolders *folders)
keys = g_hash_table_get_keys_as_array (folder->categories, NULL);
g_settings_set_strv (settings, "categories", (const gchar * const *)keys);
g_free (keys);
-
- g_object_unref (settings);
- g_free (child_path);
}
- g_free (path);
apps = gs_folders_get_nonempty_folders (folders);
g_settings_set_strv (folders->priv->settings, "folder-children",
- (const gchar * const *)apps);
- g_free (apps);
+ (const gchar * const *)apps);
}
static void
@@ -343,10 +329,9 @@ gs_folders_get_folders (GsFolders *folders)
gchar **
gs_folders_get_nonempty_folders (GsFolders *folders)
{
- GHashTable *tmp;
GHashTableIter iter;
GsFolder *folder;
- gchar **keys;
+ _cleanup_hashtable_unref_ GHashTable *tmp = NULL;
tmp = g_hash_table_new (g_str_hash, g_str_equal);
@@ -360,34 +345,30 @@ gs_folders_get_nonempty_folders (GsFolders *folders)
g_hash_table_add (tmp, folder->id);
}
- keys = (gchar **) g_hash_table_get_keys_as_array (tmp, NULL);
- g_hash_table_destroy (tmp);
-
- return keys;
+ return (gchar **) g_hash_table_get_keys_as_array (tmp, NULL);
}
static void
canonicalize_key (gchar *key)
{
- gchar *p;
-
- for (p = key; *p != 0; p++)
- {
- gchar c = *p;
-
- if (c != '-' &&
- (c < '0' || c > '9') &&
- (c < 'A' || c > 'Z') &&
- (c < 'a' || c > 'z'))
- *p = '-';
- }
+ gchar *p;
+
+ for (p = key; *p != 0; p++) {
+ gchar c = *p;
+
+ if (c != '-' &&
+ (c < '0' || c > '9') &&
+ (c < 'A' || c > 'Z') &&
+ (c < 'a' || c > 'z'))
+ *p = '-';
+ }
}
const gchar *
gs_folders_add_folder (GsFolders *folders, const gchar *id)
{
GsFolder *folder;
- gchar *key;
+ _cleanup_free_ gchar *key = NULL;
key = g_strdup (id);
canonicalize_key (key);
@@ -396,7 +377,6 @@ gs_folders_add_folder (GsFolders *folders, const gchar *id)
folder = gs_folder_new (key, id, FALSE);
g_hash_table_insert (folders->priv->folders, folder->id, folder);
}
- g_free (key);
return folder->id;
}
@@ -550,8 +530,8 @@ gs_folders_revert (GsFolders *folders)
void
gs_folders_convert (void)
{
- GSettings *settings;
- gchar **ids;
+ _cleanup_object_unref_ GSettings *settings = NULL;
+ _cleanup_strv_free_ gchar **ids = NULL;
settings = g_settings_new (APP_FOLDER_SCHEMA);
ids = g_settings_get_strv (settings, "folder-children");
@@ -632,10 +612,10 @@ gs_folders_convert (void)
GSettings *child;
g_settings_set_strv (settings, "folder-children", children);
- g_object_get (settings, "path", &path, NULL);
+ g_object_get (settings, "path", &path, NULL);
- child_path = g_strconcat (path, "folders/Utilities/", NULL);
- child = g_settings_new_with_path (APP_FOLDER_CHILD_SCHEMA, child_path);
+ child_path = g_strconcat (path, "folders/Utilities/", NULL);
+ child = g_settings_new_with_path (APP_FOLDER_CHILD_SCHEMA, child_path);
g_settings_set_string (child, "name", "X-GNOME-Utilities.directory");
g_settings_set_boolean (child, "translate", TRUE);
g_settings_set_strv (child, "categories", utilities_categories);
@@ -644,8 +624,8 @@ gs_folders_convert (void)
g_object_unref (child);
g_free (child_path);
- child_path = g_strconcat (path, "folders/Sundry/", NULL);
- child = g_settings_new_with_path (APP_FOLDER_CHILD_SCHEMA, child_path);
+ child_path = g_strconcat (path, "folders/Sundry/", NULL);
+ child = g_settings_new_with_path (APP_FOLDER_CHILD_SCHEMA, child_path);
g_settings_set_string (child, "name", "X-GNOME-Sundry.directory");
g_settings_set_boolean (child, "translate", TRUE);
g_settings_set_strv (child, "categories", sundry_categories);
@@ -655,9 +635,6 @@ gs_folders_convert (void)
g_free (child_path);
}
-
- g_strfreev (ids);
- g_object_unref (settings);
}
/* vim: set noexpandtab: */
diff --git a/src/gs-history-dialog.c b/src/gs-history-dialog.c
index 61457f6..2ec2edf 100644
--- a/src/gs-history-dialog.c
+++ b/src/gs-history-dialog.c
@@ -57,7 +57,6 @@ gs_history_dialog_set_app (GsHistoryDialog *dialog, GsApp *app)
{
GsHistoryDialogPrivate *priv = gs_history_dialog_get_instance_private (dialog);
const gchar *tmp;
- gchar *date_str;
GDateTime *datetime;
GPtrArray *history;
GtkBox *box;
@@ -70,6 +69,7 @@ gs_history_dialog_set_app (GsHistoryDialog *dialog, GsApp *app)
history = gs_app_get_history (app);
g_ptr_array_sort (history, history_sort_cb);
for (i = 0; i < history->len; i++) {
+ _cleanup_free_ gchar *date_str = NULL;
app = g_ptr_array_index (history, i);
box = GTK_BOX (gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0));
@@ -101,12 +101,12 @@ gs_history_dialog_set_app (GsHistoryDialog *dialog, GsApp *app)
}
widget = gtk_label_new (tmp);
g_object_set (widget,
- "margin-start", 20,
- "margin-end", 20,
- "margin-top", 6,
- "margin-bottom", 6,
- "xalign", 0.0,
- NULL);
+ "margin-start", 20,
+ "margin-end", 20,
+ "margin-top", 6,
+ "margin-bottom", 6,
+ "xalign", 0.0,
+ NULL);
gtk_size_group_add_widget (priv->sizegroup_state, widget);
gtk_box_pack_start (box, widget, TRUE, TRUE, 0);
@@ -120,26 +120,25 @@ gs_history_dialog_set_app (GsHistoryDialog *dialog, GsApp *app)
}
widget = gtk_label_new (date_str);
g_object_set (widget,
- "margin-start", 20,
- "margin-end", 20,
- "margin-top", 6,
- "margin-bottom", 6,
- "xalign", 0.0,
- NULL);
+ "margin-start", 20,
+ "margin-end", 20,
+ "margin-top", 6,
+ "margin-bottom", 6,
+ "xalign", 0.0,
+ NULL);
gtk_size_group_add_widget (priv->sizegroup_timestamp, widget);
gtk_box_pack_start (box, widget, TRUE, TRUE, 0);
- g_free (date_str);
g_date_time_unref (datetime);
/* add the version */
widget = gtk_label_new (gs_app_get_version (app));
g_object_set (widget,
- "margin-start", 20,
- "margin-end", 20,
- "margin-top", 6,
- "margin-bottom", 6,
- "xalign", 1.0,
- NULL);
+ "margin-start", 20,
+ "margin-end", 20,
+ "margin-top", 6,
+ "margin-bottom", 6,
+ "xalign", 1.0,
+ NULL);
gtk_size_group_add_widget (priv->sizegroup_version, widget);
gtk_box_pack_start (box, widget, TRUE, TRUE, 0);
@@ -150,8 +149,8 @@ gs_history_dialog_set_app (GsHistoryDialog *dialog, GsApp *app)
static void
update_header_func (GtkListBoxRow *row,
- GtkListBoxRow *before,
- gpointer user_data)
+ GtkListBoxRow *before,
+ gpointer user_data)
{
GtkWidget *header;
@@ -215,9 +214,9 @@ gs_history_dialog_init (GsHistoryDialog *dialog)
priv->sizegroup_version = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
gtk_list_box_set_header_func (GTK_LIST_BOX (priv->list_box),
- update_header_func,
- dialog,
- NULL);
+ update_header_func,
+ dialog,
+ NULL);
scrollbar = gtk_scrolled_window_get_vscrollbar (GTK_SCROLLED_WINDOW (priv->scrolledwindow));
g_signal_connect (scrollbar, "map", G_CALLBACK (scrollbar_mapped_cb), priv->scrolledwindow);
@@ -242,8 +241,8 @@ GtkWidget *
gs_history_dialog_new (void)
{
return GTK_WIDGET (g_object_new (GS_TYPE_HISTORY_DIALOG,
- "use-header-bar", TRUE,
- NULL));
+ "use-header-bar", TRUE,
+ NULL));
}
/* vim: set noexpandtab: */
diff --git a/src/gs-main.c b/src/gs-main.c
index 4153fc2..6f75dfc 100644
--- a/src/gs-main.c
+++ b/src/gs-main.c
@@ -28,14 +28,15 @@
#include <locale.h>
#include "gs-application.h"
+#include "gs-cleanup.h"
#include "gs-profile.h"
int
main (int argc, char **argv)
{
int status = 0;
- GsApplication *application;
- GsProfile *profile;
+ _cleanup_object_unref_ GsApplication *application = NULL;
+ _cleanup_object_unref_ GsProfile *profile = NULL;
setlocale (LC_ALL, "");
@@ -47,9 +48,7 @@ main (int argc, char **argv)
gs_profile_start (profile, "GsMain");
application = gs_application_new ();
status = g_application_run (G_APPLICATION (application), argc, argv);
- g_object_unref (application);
gs_profile_stop (profile, "GsMain");
- g_object_unref (profile);
return status;
}
diff --git a/src/gs-markdown.c b/src/gs-markdown.c
index a674dea..95cc582 100644
--- a/src/gs-markdown.c
+++ b/src/gs-markdown.c
@@ -24,6 +24,7 @@
#include <string.h>
#include <glib.h>
+#include "gs-cleanup.h"
#include "gs-markdown.h"
/*******************************************************************************
@@ -102,29 +103,26 @@ gs_markdown_to_text_line_is_rule (const gchar *line)
guint i;
guint len;
guint count = 0;
- gchar *copy = NULL;
- gboolean ret = FALSE;
+ _cleanup_free_ gchar *copy = NULL;
len = strlen (line);
if (len == 0)
- goto out;
+ return FALSE;
/* replace non-rule chars with ~ */
copy = g_strdup (line);
g_strcanon (copy, "-*_ ", '~');
for (i = 0; i < len; i++) {
if (copy[i] == '~')
- goto out;
+ return FALSE;
if (copy[i] != ' ')
count++;
}
/* if we matched, return true */
if (count >= 3)
- ret = TRUE;
-out:
- g_free (copy);
- return ret;
+ return TRUE;
+ return FALSE;
}
/**
@@ -206,25 +204,20 @@ gs_markdown_to_text_line_is_blank (const gchar *line)
{
guint i;
guint len;
- gboolean ret = FALSE;
/* a line with no characters is blank by definition */
len = strlen (line);
- if (len == 0) {
- ret = TRUE;
- goto out;
- }
+ if (len == 0)
+ return TRUE;
/* find if there are only space chars */
for (i = 0; i < len; i++) {
if (line[i] != ' ' && line[i] != '\t')
- goto out;
+ return FALSE;
}
/* if we matched, return true */
- ret = TRUE;
-out:
- return ret;
+ return TRUE;
}
/**
@@ -235,14 +228,9 @@ gs_markdown_replace (const gchar *haystack,
const gchar *needle,
const gchar *replace)
{
- gchar *new;
- gchar **split;
-
+ _cleanup_strv_free_ gchar **split = NULL;
split = g_strsplit (haystack, needle, -1);
- new = g_strjoinv (replace, split);
- g_strfreev (split);
-
- return new;
+ return g_strjoinv (replace, split);
}
/**
@@ -287,14 +275,12 @@ gs_markdown_to_text_line_formatter (const gchar *line,
gchar *start = NULL;
gchar *middle = NULL;
gchar *end = NULL;
- gchar *copy = NULL;
- gchar *data = NULL;
- gchar *temp;
+ _cleanup_free_ gchar *copy = NULL;
/* needed to know for shifts */
len = strlen (formatter);
if (len == 0)
- goto out;
+ return NULL;
/* find sections */
copy = g_strdup (line);
@@ -312,17 +298,14 @@ gs_markdown_to_text_line_formatter (const gchar *line,
/* if we found, replace and keep looking for the same string */
if (start != NULL && middle != NULL && end != NULL) {
+ _cleanup_free_ gchar *temp = NULL;
temp = g_strdup_printf ("%s%s%s%s%s", start, left, middle, right, end);
/* recursive */
- data = gs_markdown_to_text_line_formatter (temp, formatter, left, right);
- g_free (temp);
- } else {
- /* not found, keep return as-is */
- data = g_strdup (line);
+ return gs_markdown_to_text_line_formatter (temp, formatter, left, right);
}
-out:
- g_free (copy);
- return data;
+
+ /* not found, keep return as-is */
+ return g_strdup (line);
}
/**
@@ -391,16 +374,14 @@ gs_markdown_to_text_line_format (GsMarkdown *self, const gchar *line)
GString *string;
GsMarkdownPrivate *priv = gs_markdown_get_instance_private (self);
gboolean mode = FALSE;
- gchar **codes = NULL;
gchar *text;
guint i;
+ _cleanup_strv_free_ gchar **codes = NULL;
/* optimise the trivial case where we don't have any code tags */
text = strstr (line, "`");
- if (text == NULL) {
- text = gs_markdown_to_text_line_format_sections (self, line);
- goto out;
- }
+ if (text == NULL)
+ return gs_markdown_to_text_line_format_sections (self, line);
/* we want to parse the code sections without formatting */
codes = g_strsplit (line, "`", -1);
@@ -419,10 +400,7 @@ gs_markdown_to_text_line_format (GsMarkdown *self, const gchar *line)
mode = FALSE;
}
}
- text = g_string_free (string, FALSE);
-out:
- g_strfreev (codes);
- return text;
+ return g_string_free (string, FALSE);
}
/**
@@ -431,7 +409,7 @@ out:
static gboolean
gs_markdown_add_pending (GsMarkdown *self, const gchar *line)
{
- gchar *copy;
+ _cleanup_free_ gchar *copy = NULL;
GsMarkdownPrivate *priv = gs_markdown_get_instance_private (self);
/* would put us over the limit */
@@ -445,8 +423,6 @@ gs_markdown_add_pending (GsMarkdown *self, const gchar *line)
/* append */
g_string_append_printf (priv->pending, "%s ", copy);
-
- g_free (copy);
return TRUE;
}
@@ -456,15 +432,12 @@ gs_markdown_add_pending (GsMarkdown *self, const gchar *line)
static gboolean
gs_markdown_add_pending_header (GsMarkdown *self, const gchar *line)
{
- gchar *copy;
- gboolean ret;
+ _cleanup_free_ gchar *copy = NULL;
/* strip trailing # */
copy = g_strdup (line);
g_strdelimit (copy, "#", ' ');
- ret = gs_markdown_add_pending (self, copy);
- g_free (copy);
- return ret;
+ return gs_markdown_add_pending (self, copy);
}
/**
@@ -480,14 +453,13 @@ gs_markdown_count_chars_in_word (const gchar *text, gchar find)
/* get length */
len = strlen (text);
if (len == 0)
- goto out;
+ return 0;
/* find matching chars */
for (i = 0; i < len; i++) {
if (text[i] == find)
count++;
}
-out:
return count;
}
@@ -542,8 +514,8 @@ gs_markdown_word_auto_format_code (const gchar *text)
{
guint i;
gchar *temp;
- gchar **words;
gboolean ret = FALSE;
+ _cleanup_strv_free_ gchar **words = NULL;
/* split sentence up with space */
words = g_strsplit (text, " ", -1);
@@ -559,16 +531,11 @@ gs_markdown_word_auto_format_code (const gchar *text)
}
/* no replacements, so just return a copy */
- if (!ret) {
- temp = g_strdup (text);
- goto out;
- }
+ if (!ret)
+ return g_strdup (text);
/* join the array back into a string */
- temp = g_strjoinv (" ", words);
-out:
- g_strfreev (words);
- return temp;
+ return g_strjoinv (" ", words);
}
/**
@@ -594,8 +561,8 @@ gs_markdown_word_auto_format_urls (const gchar *text)
{
guint i;
gchar *temp;
- gchar **words;
gboolean ret = FALSE;
+ _cleanup_strv_free_ gchar **words = NULL;
/* split sentence up with space */
words = g_strsplit (text, " ", -1);
@@ -612,16 +579,11 @@ gs_markdown_word_auto_format_urls (const gchar *text)
}
/* no replacements, so just return a copy */
- if (!ret) {
- temp = g_strdup (text);
- goto out;
- }
+ if (!ret)
+ return g_strdup (text);
/* join the array back into a string */
- temp = g_strjoinv (" ", words);
-out:
- g_strfreev (words);
- return temp;
+ return g_strjoinv (" ", words);
}
/**
@@ -630,9 +592,9 @@ out:
static void
gs_markdown_flush_pending (GsMarkdown *self)
{
- gchar *copy;
- gchar *temp;
GsMarkdownPrivate *priv = gs_markdown_get_instance_private (self);
+ _cleanup_free_ gchar *copy = NULL;
+ _cleanup_free_ gchar *temp = NULL;
/* no data yet */
if (priv->mode == GS_MARKDOWN_MODE_UNKNOWN)
@@ -704,8 +666,6 @@ gs_markdown_flush_pending (GsMarkdown *self)
/* clear */
g_string_truncate (priv->pending, 0);
- g_free (copy);
- g_free (temp);
}
/**
@@ -939,10 +899,10 @@ gs_markdown_parse (GsMarkdown *self, const gchar *markdown)
{
GsMarkdownPrivate *priv = gs_markdown_get_instance_private (self);
gboolean ret;
- gchar **lines;
gchar *temp;
guint i;
guint len;
+ _cleanup_strv_free_ gchar **lines = NULL;
g_return_val_if_fail (GS_IS_MARKDOWN (self), NULL);
@@ -962,7 +922,6 @@ gs_markdown_parse (GsMarkdown *self, const gchar *markdown)
if (!ret)
break;
}
- g_strfreev (lines);
gs_markdown_flush_pending (self);
/* remove trailing \n */
diff --git a/src/gs-offline-updates.c b/src/gs-offline-updates.c
index 9004327..7803d37 100644
--- a/src/gs-offline-updates.c
+++ b/src/gs-offline-updates.c
@@ -24,6 +24,7 @@
#include <glib/gi18n.h>
#include <packagekit-glib2/packagekit.h>
+#include "gs-cleanup.h"
#include "gs-offline-updates.h"
#include "gs-utils.h"
@@ -32,22 +33,22 @@ gs_offline_updates_show_error (void)
{
const gchar *title;
gboolean show_geeky = FALSE;
- GString *msg;
GtkWidget *dialog;
- GError *error = NULL;
- PkResults *results = NULL;
- PkError *pk_error = NULL;
+ _cleanup_error_free_ GError *error = NULL;
+ _cleanup_object_unref_ PkError *pk_error = NULL;
+ _cleanup_object_unref_ PkResults *results = NULL;
+ _cleanup_string_free_ GString *msg = NULL;
results = pk_offline_get_results (NULL);
if (results == NULL)
- goto out;
+ return;
pk_error = pk_results_get_error_code (results);
if (pk_error == NULL)
- goto out;
+ return;
/* can this happen in reality? */
if (pk_results_get_exit_code (results) == PK_EXIT_ENUM_SUCCESS)
- goto out;
+ return;
/* TRANSLATORS: this is when the offline update failed */
title = _("Failed To Update");
@@ -140,14 +141,7 @@ gs_offline_updates_show_error (void)
if (!pk_offline_clear_results (NULL, &error)) {
g_warning ("Failure clearing offline update message: %s",
error->message);
- g_error_free (error);
}
- g_string_free (msg, TRUE);
-out:
- if (pk_error != NULL)
- g_object_unref (pk_error);
- if (results != NULL)
- g_object_unref (results);
}
/* vim: set noexpandtab: */
diff --git a/src/gs-plugin-loader.c b/src/gs-plugin-loader.c
index dfc4a06..34fd073 100644
--- a/src/gs-plugin-loader.c
+++ b/src/gs-plugin-loader.c
@@ -23,6 +23,7 @@
#include <glib/gi18n.h>
+#include "gs-cleanup.h"
#include "gs-plugin-loader.h"
#include "gs-plugin.h"
#include "gs-profile.h"
@@ -164,7 +165,7 @@ gs_plugin_loader_run_refine_plugin (GsPluginLoader *plugin_loader,
const gchar *function_name = "gs_plugin_refine";
gboolean exists;
gboolean ret = TRUE;
- gchar *profile_id = NULL;
+ _cleanup_free_ gchar *profile_id = NULL;
/* load the symbol */
exists = g_module_symbol (plugin->module,
@@ -212,7 +213,6 @@ out:
gs_profile_stop (plugin_loader->priv->profile, profile_id);
gs_plugin_status_update (plugin, NULL, GS_PLUGIN_STATUS_FINISHED);
}
- g_free (profile_id);
return ret;
}
@@ -338,7 +338,7 @@ gs_plugin_loader_run_results_plugin (GsPluginLoader *plugin_loader,
GsPluginResultsFunc plugin_func = NULL;
gboolean exists;
gboolean ret = TRUE;
- gchar *profile_id = NULL;
+ _cleanup_free_ gchar *profile_id = NULL;
/* get symbol */
exists = g_module_symbol (plugin->module,
@@ -360,7 +360,6 @@ out:
gs_plugin_status_update (plugin, NULL, GS_PLUGIN_STATUS_FINISHED);
gs_profile_stop (plugin_loader->priv->profile, profile_id);
}
- g_free (profile_id);
return ret;
}
@@ -375,10 +374,10 @@ gs_plugin_loader_run_results (GsPluginLoader *plugin_loader,
GError **error)
{
gboolean ret = TRUE;
- gchar *profile_id_parent;
GList *list = NULL;
GsPlugin *plugin;
guint i;
+ _cleanup_free_ gchar *profile_id_parent = NULL;
g_return_val_if_fail (GS_IS_PLUGIN_LOADER (plugin_loader), NULL);
g_return_val_if_fail (function_name != NULL, NULL);
@@ -436,7 +435,6 @@ gs_plugin_loader_run_results (GsPluginLoader *plugin_loader,
}
out:
gs_profile_stop (plugin_loader->priv->profile, profile_id_parent);
- g_free (profile_id_parent);
if (!ret) {
gs_plugin_list_free (list);
list = NULL;
@@ -460,7 +458,7 @@ gs_plugin_loader_run_popular_plugin (GsPluginLoader *plugin_loader,
GsPluginPopularFunc plugin_func = NULL;
gboolean exists;
gboolean ret = TRUE;
- gchar *profile_id = NULL;
+ _cleanup_free_ gchar *profile_id = NULL;
/* get symbol */
exists = g_module_symbol (plugin->module,
@@ -482,7 +480,6 @@ out:
gs_plugin_status_update (plugin, NULL, GS_PLUGIN_STATUS_FINISHED);
gs_profile_stop (plugin_loader->priv->profile, profile_id);
}
- g_free (profile_id);
return ret;
}
@@ -499,10 +496,10 @@ gs_plugin_loader_run_popular (GsPluginLoader *plugin_loader,
GError **error)
{
gboolean ret = TRUE;
- gchar *profile_id_parent;
GList *list = NULL;
GsPlugin *plugin;
guint i;
+ _cleanup_free_ gchar *profile_id_parent = NULL;
g_return_val_if_fail (GS_IS_PLUGIN_LOADER (plugin_loader), NULL);
g_return_val_if_fail (function_name != NULL, NULL);
@@ -562,7 +559,6 @@ gs_plugin_loader_run_popular (GsPluginLoader *plugin_loader,
}
out:
gs_profile_stop (plugin_loader->priv->profile, profile_id_parent);
- g_free (profile_id_parent);
if (!ret) {
gs_plugin_list_free (list);
list = NULL;
@@ -757,7 +753,7 @@ gs_plugin_loader_run_action_plugin (GsPluginLoader *plugin_loader,
GsPluginActionFunc plugin_func = NULL;
gboolean exists;
gboolean ret = TRUE;
- gchar *profile_id = NULL;
+ _cleanup_free_ gchar *profile_id = NULL;
exists = g_module_symbol (plugin->module,
function_name,
@@ -787,7 +783,6 @@ out:
gs_plugin_status_update (plugin, NULL, GS_PLUGIN_STATUS_FINISHED);
gs_profile_stop (plugin_loader->priv->profile, profile_id);
}
- g_free (profile_id);
return ret;
}
@@ -801,7 +796,7 @@ gs_plugin_loader_run_action (GsPluginLoader *plugin_loader,
GCancellable *cancellable,
GError **error)
{
- gboolean ret = TRUE;
+ gboolean ret;
gboolean anything_ran = FALSE;
GsPlugin *plugin;
guint i;
@@ -811,11 +806,8 @@ gs_plugin_loader_run_action (GsPluginLoader *plugin_loader,
plugin = g_ptr_array_index (plugin_loader->priv->plugins, i);
if (!plugin->enabled)
continue;
- ret = g_cancellable_set_error_if_cancelled (cancellable, error);
- if (ret) {
- ret = FALSE;
- goto out;
- }
+ if (g_cancellable_set_error_if_cancelled (cancellable, error))
+ return FALSE;
ret = gs_plugin_loader_run_action_plugin (plugin_loader,
plugin,
app,
@@ -823,22 +815,20 @@ gs_plugin_loader_run_action (GsPluginLoader *plugin_loader,
cancellable,
error);
if (!ret)
- goto out;
+ return FALSE;
anything_ran = TRUE;
}
/* nothing ran */
if (!anything_ran) {
- ret = FALSE;
g_set_error (error,
GS_PLUGIN_LOADER_ERROR,
GS_PLUGIN_LOADER_ERROR_FAILED,
"no plugin could handle %s",
function_name);
- goto out;
+ return FALSE;
}
-out:
- return ret;
+ return TRUE;
}
/******************************************************************************/
@@ -901,12 +891,11 @@ static GList *
gs_plugin_loader_add_os_update_item (GList *list)
{
gboolean has_os_update = FALSE;
- GError *error = NULL;
- GdkPixbuf *pixbuf = NULL;
GList *l;
- GList *list_new = list;
GsApp *app_os;
GsApp *app_tmp;
+ _cleanup_error_free_ GError *error = NULL;
+ _cleanup_object_unref_ GdkPixbuf *pixbuf = NULL;
/* do we have any packages left that are not apps? */
for (l = list; l != NULL; l = l->next) {
@@ -917,7 +906,7 @@ gs_plugin_loader_add_os_update_item (GList *list)
}
}
if (!has_os_update)
- goto out;
+ return list;
/* create new meta object */
app_os = gs_app_new ("os-update.virtual");
@@ -953,15 +942,10 @@ gs_plugin_loader_add_os_update_item (GList *list)
if (pixbuf == NULL) {
g_warning ("Failed to find software-update-available-symbolic: %s",
error->message);
- g_error_free (error);
} else {
gs_app_set_pixbuf (app_os, pixbuf);
}
- list_new = g_list_prepend (list, app_os);
-out:
- if (pixbuf != NULL)
- g_object_unref (pixbuf);
- return list_new;
+ return g_list_prepend (list, app_os);
}
/**
@@ -974,9 +958,9 @@ gs_plugin_loader_get_updates_thread_cb (GTask *task,
GCancellable *cancellable)
{
const gchar *method_name = "gs_plugin_add_updates";
- GError *error = NULL;
GsPluginLoaderAsyncState *state = (GsPluginLoaderAsyncState *) task_data;
GsPluginLoader *plugin_loader = GS_PLUGIN_LOADER (object);
+ GError *error = NULL;
/* do things that would block */
if ((state->flags & GS_PLUGIN_REFINE_FLAGS_USE_HISTORY) > 0)
@@ -989,7 +973,7 @@ gs_plugin_loader_get_updates_thread_cb (GTask *task,
&error);
if (error != NULL) {
g_task_return_error (task, error);
- goto out;
+ return;
}
/* filter package list */
@@ -1006,16 +990,14 @@ gs_plugin_loader_get_updates_thread_cb (GTask *task,
gs_plugin_list_filter (&state->list, gs_plugin_loader_app_is_valid, NULL);
if (state->list == NULL) {
g_task_return_new_error (task,
- GS_PLUGIN_LOADER_ERROR,
- GS_PLUGIN_LOADER_ERROR_NO_RESULTS,
- "no updates to show after invalid");
- goto out;
+ GS_PLUGIN_LOADER_ERROR,
+ GS_PLUGIN_LOADER_ERROR_NO_RESULTS,
+ "no updates to show after invalid");
+ return;
}
/* success */
g_task_return_pointer (task, gs_plugin_list_copy (state->list), (GDestroyNotify) gs_plugin_list_free);
-out:
- return;
}
/**
@@ -1048,7 +1030,7 @@ gs_plugin_loader_get_updates_async (GsPluginLoader *plugin_loader,
gpointer user_data)
{
GsPluginLoaderAsyncState *state;
- GTask *task;
+ _cleanup_object_unref_ GTask *task = NULL;
g_return_if_fail (GS_IS_PLUGIN_LOADER (plugin_loader));
g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
@@ -1062,7 +1044,6 @@ gs_plugin_loader_get_updates_async (GsPluginLoader *plugin_loader,
g_task_set_task_data (task, state, (GDestroyNotify) gs_plugin_loader_free_async_state);
g_task_set_return_on_cancel (task, TRUE);
g_task_run_in_thread (task, gs_plugin_loader_get_updates_thread_cb);
- g_object_unref (task);
}
/**
@@ -1094,9 +1075,9 @@ gs_plugin_loader_get_sources_thread_cb (GTask *task,
gpointer task_data,
GCancellable *cancellable)
{
- GError *error = NULL;
GsPluginLoaderAsyncState *state = task_data;
GsPluginLoader *plugin_loader = GS_PLUGIN_LOADER (object);
+ GError *error = NULL;
state->list = gs_plugin_loader_run_results (plugin_loader,
"gs_plugin_add_sources",
@@ -1105,7 +1086,7 @@ gs_plugin_loader_get_sources_thread_cb (GTask *task,
&error);
if (error != NULL) {
g_task_return_error (task, error);
- goto out;
+ return;
}
/* filter package list */
@@ -1117,16 +1098,14 @@ gs_plugin_loader_get_sources_thread_cb (GTask *task,
/* none left? */
if (state->list == NULL) {
g_task_return_new_error (task,
- GS_PLUGIN_LOADER_ERROR,
- GS_PLUGIN_LOADER_ERROR_NO_RESULTS,
- "no sources to show");
- goto out;
+ GS_PLUGIN_LOADER_ERROR,
+ GS_PLUGIN_LOADER_ERROR_NO_RESULTS,
+ "no sources to show");
+ return;
}
/* success */
g_task_return_pointer (task, gs_plugin_list_copy (state->list), (GDestroyNotify) gs_plugin_list_free);
-out:
- return;
}
/**
@@ -1146,7 +1125,7 @@ gs_plugin_loader_get_sources_async (GsPluginLoader *plugin_loader,
gpointer user_data)
{
GsPluginLoaderAsyncState *state;
- GTask *task;
+ _cleanup_object_unref_ GTask *task = NULL;
g_return_if_fail (GS_IS_PLUGIN_LOADER (plugin_loader));
g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
@@ -1160,7 +1139,6 @@ gs_plugin_loader_get_sources_async (GsPluginLoader *plugin_loader,
g_task_set_task_data (task, state, (GDestroyNotify) gs_plugin_loader_free_async_state);
g_task_set_return_on_cancel (task, TRUE);
g_task_run_in_thread (task, gs_plugin_loader_get_sources_thread_cb);
- g_object_unref (task);
}
/**
@@ -1192,9 +1170,9 @@ gs_plugin_loader_get_installed_thread_cb (GTask *task,
gpointer task_data,
GCancellable *cancellable)
{
- GError *error = NULL;
GsPluginLoader *plugin_loader = GS_PLUGIN_LOADER (object);
GsPluginLoaderAsyncState *state = (GsPluginLoaderAsyncState *) task_data;
+ GError *error = NULL;
/* do things that would block */
state->list = gs_plugin_loader_run_results (plugin_loader,
@@ -1204,7 +1182,7 @@ gs_plugin_loader_get_installed_thread_cb (GTask *task,
&error);
if (error != NULL) {
g_task_return_error (task, error);
- goto out;
+ return;
}
state->list = g_list_concat (state->list, g_list_copy_deep (plugin_loader->priv->queued_installs,
(GCopyFunc)g_object_ref, NULL));
@@ -1213,16 +1191,14 @@ gs_plugin_loader_get_installed_thread_cb (GTask *task,
gs_plugin_list_filter (&state->list, gs_plugin_loader_app_is_valid, NULL);
if (state->list == NULL) {
g_task_return_new_error (task,
- GS_PLUGIN_LOADER_ERROR,
- GS_PLUGIN_LOADER_ERROR_NO_RESULTS,
- "no installed applications to show after invalid");
- goto out;
+ GS_PLUGIN_LOADER_ERROR,
+ GS_PLUGIN_LOADER_ERROR_NO_RESULTS,
+ "no installed applications to show after invalid");
+ return;
}
/* success */
g_task_return_pointer (task, gs_plugin_list_copy (state->list), (GDestroyNotify) gs_plugin_list_free);
-out:
- return;
}
/**
@@ -1253,7 +1229,7 @@ gs_plugin_loader_get_installed_async (GsPluginLoader *plugin_loader,
gpointer user_data)
{
GsPluginLoaderAsyncState *state;
- GTask *task;
+ _cleanup_object_unref_ GTask *task = NULL;
g_return_if_fail (GS_IS_PLUGIN_LOADER (plugin_loader));
g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
@@ -1267,7 +1243,6 @@ gs_plugin_loader_get_installed_async (GsPluginLoader *plugin_loader,
g_task_set_task_data (task, state, (GDestroyNotify) gs_plugin_loader_free_async_state);
g_task_set_return_on_cancel (task, TRUE);
g_task_run_in_thread (task, gs_plugin_loader_get_installed_thread_cb);
- g_object_unref (task);
}
/**
@@ -1295,13 +1270,13 @@ gs_plugin_loader_get_installed_finish (GsPluginLoader *plugin_loader,
**/
static void
gs_plugin_loader_get_popular_thread_cb (GTask *task,
- gpointer object,
- gpointer task_data,
- GCancellable *cancellable)
+ gpointer object,
+ gpointer task_data,
+ GCancellable *cancellable)
{
- GError *error = NULL;
GsPluginLoader *plugin_loader = GS_PLUGIN_LOADER (object);
GsPluginLoaderAsyncState *state = (GsPluginLoaderAsyncState *) task_data;
+ GError *error = NULL;
/* do things that would block */
state->list = gs_plugin_loader_run_popular (plugin_loader,
@@ -1313,7 +1288,7 @@ gs_plugin_loader_get_popular_thread_cb (GTask *task,
&error);
if (error != NULL) {
g_task_return_error (task, error);
- goto out;
+ return;
}
/* filter package list */
@@ -1322,10 +1297,10 @@ gs_plugin_loader_get_popular_thread_cb (GTask *task,
gs_plugin_list_filter (&state->list, gs_plugin_loader_filter_qt_for_gtk, NULL);
if (state->list == NULL) {
g_task_return_new_error (task,
- GS_PLUGIN_LOADER_ERROR,
- GS_PLUGIN_LOADER_ERROR_NO_RESULTS,
- "no popular apps to show");
- goto out;
+ GS_PLUGIN_LOADER_ERROR,
+ GS_PLUGIN_LOADER_ERROR_NO_RESULTS,
+ "no popular apps to show");
+ return;
}
/* shuffle around the list */
@@ -1333,8 +1308,6 @@ gs_plugin_loader_get_popular_thread_cb (GTask *task,
/* success */
g_task_return_pointer (task, gs_plugin_list_copy (state->list), (GDestroyNotify) gs_plugin_list_free);
-out:
- return;
}
/**
@@ -1350,7 +1323,7 @@ gs_plugin_loader_get_popular_async (GsPluginLoader *plugin_loader,
gpointer user_data)
{
GsPluginLoaderAsyncState *state;
- GTask *task;
+ _cleanup_object_unref_ GTask *task = NULL;
g_return_if_fail (GS_IS_PLUGIN_LOADER (plugin_loader));
g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
@@ -1366,7 +1339,6 @@ gs_plugin_loader_get_popular_async (GsPluginLoader *plugin_loader,
g_task_set_task_data (task, state, (GDestroyNotify) gs_plugin_loader_free_async_state);
g_task_set_return_on_cancel (task, TRUE);
g_task_run_in_thread (task, gs_plugin_loader_get_popular_thread_cb);
- g_object_unref (task);
}
/**
@@ -1406,13 +1378,13 @@ gs_plugin_loader_featured_debug (GsApp *app, gpointer user_data)
**/
static void
gs_plugin_loader_get_featured_thread_cb (GTask *task,
- gpointer object,
- gpointer task_data,
- GCancellable *cancellable)
+ gpointer object,
+ gpointer task_data,
+ GCancellable *cancellable)
{
- GError *error = NULL;
GsPluginLoader *plugin_loader = GS_PLUGIN_LOADER (object);
GsPluginLoaderAsyncState *state = (GsPluginLoaderAsyncState *) task_data;
+ GError *error = NULL;
/* do things that would block */
state->list = gs_plugin_loader_run_results (plugin_loader,
@@ -1422,7 +1394,7 @@ gs_plugin_loader_get_featured_thread_cb (GTask *task,
&error);
if (error != NULL) {
g_task_return_error (task, error);
- goto out;
+ return;
}
/* filter package list */
@@ -1434,16 +1406,14 @@ gs_plugin_loader_get_featured_thread_cb (GTask *task,
}
if (state->list == NULL) {
g_task_return_new_error (task,
- GS_PLUGIN_LOADER_ERROR,
- GS_PLUGIN_LOADER_ERROR_NO_RESULTS,
- "no featured apps to show");
- goto out;
+ GS_PLUGIN_LOADER_ERROR,
+ GS_PLUGIN_LOADER_ERROR_NO_RESULTS,
+ "no featured apps to show");
+ return;
}
/* success */
g_task_return_pointer (task, gs_plugin_list_copy (state->list), (GDestroyNotify) gs_plugin_list_free);
-out:
- return;
}
/**
@@ -1475,7 +1445,7 @@ gs_plugin_loader_get_featured_async (GsPluginLoader *plugin_loader,
gpointer user_data)
{
GsPluginLoaderAsyncState *state;
- GTask *task;
+ _cleanup_object_unref_ GTask *task = NULL;
g_return_if_fail (GS_IS_PLUGIN_LOADER (plugin_loader));
g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
@@ -1489,7 +1459,6 @@ gs_plugin_loader_get_featured_async (GsPluginLoader *plugin_loader,
g_task_set_task_data (task, state, (GDestroyNotify) gs_plugin_loader_free_async_state);
g_task_set_return_on_cancel (task, TRUE);
g_task_run_in_thread (task, gs_plugin_loader_get_featured_thread_cb);
- g_object_unref (task);
}
/**
@@ -1518,11 +1487,11 @@ gs_plugin_loader_get_featured_finish (GsPluginLoader *plugin_loader,
static gboolean
gs_plugin_loader_convert_unavailable_app (GsApp *app, const gchar *search)
{
- AsIcon *icon;
GPtrArray *keywords;
- GString *tmp;
const gchar *keyword;
guint i;
+ _cleanup_string_free_ GString *tmp = NULL;
+ _cleanup_object_unref_ AsIcon *icon = NULL;
/* is the search string one of the codec keywords */
keywords = gs_app_get_keywords (app);
@@ -1551,8 +1520,6 @@ gs_plugin_loader_convert_unavailable_app (GsApp *app, const gchar *search)
as_icon_set_name (icon, "dialog-question-symbolic", -1);
gs_app_set_icon (app, icon);
gs_app_load_icon (app, 1, NULL);
- g_string_free (tmp, TRUE);
- g_object_unref (icon);
return TRUE;
}
@@ -1564,7 +1531,6 @@ gs_plugin_loader_convert_unavailable (GList *list, const gchar *search)
{
GList *l;
GsApp *app;
- gboolean ret;
for (l = list; l != NULL; l = l->next) {
app = GS_APP (l->data);
@@ -1579,8 +1545,7 @@ gs_plugin_loader_convert_unavailable (GList *list, const gchar *search)
continue;
/* only convert the first unavailable codec */
- ret = gs_plugin_loader_convert_unavailable_app (app, search);
- if (ret)
+ if (gs_plugin_loader_convert_unavailable_app (app, search))
break;
}
}
@@ -1596,14 +1561,14 @@ gs_plugin_loader_search_thread_cb (GTask *task,
{
const gchar *function_name = "gs_plugin_add_search";
gboolean ret = TRUE;
- gchar *profile_id = NULL;
GError *error = NULL;
GsPluginLoaderAsyncState *state = (GsPluginLoaderAsyncState *) task_data;
GsPluginLoader *plugin_loader = GS_PLUGIN_LOADER (object);
GsPlugin *plugin;
GsPluginSearchFunc plugin_func = NULL;
- gchar **values;
guint i;
+ _cleanup_free_ gchar *profile_id = NULL;
+ _cleanup_strv_free_ gchar **values = NULL;
/* run each plugin */
values = g_str_tokenize_and_fold (state->value, NULL, NULL);
@@ -1662,20 +1627,17 @@ gs_plugin_loader_search_thread_cb (GTask *task,
}
if (state->list == NULL) {
g_task_return_new_error (task,
- GS_PLUGIN_LOADER_ERROR,
- GS_PLUGIN_LOADER_ERROR_NO_RESULTS,
- "no search results to show");
+ GS_PLUGIN_LOADER_ERROR,
+ GS_PLUGIN_LOADER_ERROR_NO_RESULTS,
+ "no search results to show");
goto out;
}
/* success */
g_task_return_pointer (task, gs_plugin_list_copy (state->list), (GDestroyNotify) gs_plugin_list_free);
out:
- if (profile_id != NULL) {
+ if (profile_id != NULL)
gs_profile_stop (plugin_loader->priv->profile, profile_id);
- g_free (profile_id);
- }
- g_strfreev (values);
}
/**
@@ -1708,7 +1670,7 @@ gs_plugin_loader_search_async (GsPluginLoader *plugin_loader,
gpointer user_data)
{
GsPluginLoaderAsyncState *state;
- GTask *task;
+ _cleanup_object_unref_ GTask *task = NULL;
g_return_if_fail (GS_IS_PLUGIN_LOADER (plugin_loader));
g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
@@ -1723,7 +1685,6 @@ gs_plugin_loader_search_async (GsPluginLoader *plugin_loader,
g_task_set_task_data (task, state, (GDestroyNotify) gs_plugin_loader_free_async_state);
g_task_set_return_on_cancel (task, TRUE);
g_task_run_in_thread (task, gs_plugin_loader_search_thread_cb);
- g_object_unref (task);
}
/**
@@ -1767,7 +1728,6 @@ gs_plugin_loader_get_categories_thread_cb (GTask *task,
{
const gchar *function_name = "gs_plugin_add_categories";
gboolean ret = TRUE;
- gchar *profile_id = NULL;
GError *error = NULL;
GsPluginLoaderAsyncState *state = (GsPluginLoaderAsyncState *) task_data;
GsPluginLoader *plugin_loader = GS_PLUGIN_LOADER (object);
@@ -1775,6 +1735,7 @@ gs_plugin_loader_get_categories_thread_cb (GTask *task,
GsPluginResultsFunc plugin_func = NULL;
GList *l;
guint i;
+ _cleanup_free_ gchar *profile_id = NULL;
/* run each plugin */
for (i = 0; i < plugin_loader->priv->plugins->len; i++) {
@@ -1810,20 +1771,17 @@ gs_plugin_loader_get_categories_thread_cb (GTask *task,
/* success */
if (state->list == NULL) {
g_task_return_new_error (task,
- GS_PLUGIN_LOADER_ERROR,
- GS_PLUGIN_LOADER_ERROR_NO_RESULTS,
- "no categories to show");
+ GS_PLUGIN_LOADER_ERROR,
+ GS_PLUGIN_LOADER_ERROR_NO_RESULTS,
+ "no categories to show");
goto out;
}
/* success */
g_task_return_pointer (task, gs_plugin_list_copy (state->list), (GDestroyNotify) gs_plugin_list_free);
out:
- if (profile_id != NULL) {
+ if (profile_id != NULL)
gs_profile_stop (plugin_loader->priv->profile, profile_id);
- g_free (profile_id);
- }
- return;
}
/**
@@ -1840,7 +1798,7 @@ gs_plugin_loader_get_categories_async (GsPluginLoader *plugin_loader,
gpointer user_data)
{
GsPluginLoaderAsyncState *state;
- GTask *task;
+ _cleanup_object_unref_ GTask *task = NULL;
g_return_if_fail (GS_IS_PLUGIN_LOADER (plugin_loader));
g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
@@ -1854,7 +1812,6 @@ gs_plugin_loader_get_categories_async (GsPluginLoader *plugin_loader,
g_task_set_task_data (task, state, (GDestroyNotify) gs_plugin_loader_free_async_state);
g_task_set_return_on_cancel (task, TRUE);
g_task_run_in_thread (task, gs_plugin_loader_get_categories_thread_cb);
- g_object_unref (task);
}
/**
@@ -1888,13 +1845,13 @@ 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 = NULL;
GError *error = NULL;
GsPluginLoaderAsyncState *state = (GsPluginLoaderAsyncState *) task_data;
GsPluginLoader *plugin_loader = GS_PLUGIN_LOADER (object);
GsPlugin *plugin;
GsPluginCategoryFunc plugin_func = NULL;
guint i;
+ _cleanup_free_ gchar *profile_id = NULL;
/* run each plugin */
for (i = 0; i < plugin_loader->priv->plugins->len; i++) {
@@ -1944,9 +1901,9 @@ gs_plugin_loader_get_category_apps_thread_cb (GTask *task,
gs_plugin_list_filter (&state->list, gs_plugin_loader_get_app_is_compatible, plugin_loader);
if (state->list == NULL) {
g_task_return_new_error (task,
- GS_PLUGIN_LOADER_ERROR,
- GS_PLUGIN_LOADER_ERROR_NO_RESULTS,
- "no get_category_apps results to show");
+ GS_PLUGIN_LOADER_ERROR,
+ GS_PLUGIN_LOADER_ERROR_NO_RESULTS,
+ "no get_category_apps results to show");
goto out;
}
@@ -1956,11 +1913,8 @@ 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) {
+ if (profile_id != NULL)
gs_profile_stop (plugin_loader->priv->profile, profile_id);
- g_free (profile_id);
- }
- return;
}
/**
@@ -1993,7 +1947,7 @@ gs_plugin_loader_get_category_apps_async (GsPluginLoader *plugin_loader,
gpointer user_data)
{
GsPluginLoaderAsyncState *state;
- GTask *task;
+ _cleanup_object_unref_ GTask *task = NULL;
g_return_if_fail (GS_IS_PLUGIN_LOADER (plugin_loader));
g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
@@ -2008,7 +1962,6 @@ gs_plugin_loader_get_category_apps_async (GsPluginLoader *plugin_loader,
g_task_set_task_data (task, state, (GDestroyNotify) gs_plugin_loader_free_async_state);
g_task_set_return_on_cancel (task, TRUE);
g_task_run_in_thread (task, gs_plugin_loader_get_category_apps_thread_cb);
- g_object_unref (task);
}
/**
@@ -2048,11 +2001,11 @@ gs_plugin_loader_app_refine_thread_cb (GTask *task,
gs_plugin_add_app (&list, state->app);
ret = gs_plugin_loader_run_refine (plugin_loader,
- NULL,
- &list,
- state->flags,
- cancellable,
- &error);
+ NULL,
+ &list,
+ state->flags,
+ cancellable,
+ &error);
if (!ret) {
g_task_return_error (task, error);
goto out;
@@ -2072,14 +2025,14 @@ out:
**/
void
gs_plugin_loader_app_refine_async (GsPluginLoader *plugin_loader,
- GsApp *app,
- GsPluginRefineFlags flags,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data)
+ GsApp *app,
+ GsPluginRefineFlags flags,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
{
GsPluginLoaderAsyncState *state;
- GTask *task;
+ _cleanup_object_unref_ GTask *task = NULL;
g_return_if_fail (GS_IS_PLUGIN_LOADER (plugin_loader));
g_return_if_fail (GS_IS_APP (app));
@@ -2095,7 +2048,6 @@ gs_plugin_loader_app_refine_async (GsPluginLoader *plugin_loader,
g_task_set_task_data (task, state, (GDestroyNotify) gs_plugin_loader_free_async_state);
g_task_set_return_on_cancel (task, TRUE);
g_task_run_in_thread (task, gs_plugin_loader_app_refine_thread_cb);
- g_object_unref (task);
}
/**
@@ -2151,10 +2103,10 @@ gs_plugin_loader_app_action_thread_cb (GTask *task,
/* perform action */
ret = gs_plugin_loader_run_action (plugin_loader,
- state->app,
- state->function_name,
- cancellable,
- &error);
+ state->app,
+ state->function_name,
+ cancellable,
+ &error);
if (ret) {
if (state->state_success != AS_APP_STATE_UNKNOWN) {
gs_app_set_state (state->app, state->state_success);
@@ -2192,12 +2144,11 @@ static gboolean
load_install_queue (GsPluginLoader *plugin_loader, GError **error)
{
GList *list = NULL;
- GsApp *app;
gboolean ret = TRUE;
- gchar **names = NULL;
- gchar *contents = NULL;
- gchar *file;
guint i;
+ _cleanup_free_ gchar *contents = NULL;
+ _cleanup_free_ gchar *file = NULL;
+ _cleanup_strv_free_ gchar **names = NULL;
/* load from file */
file = g_build_filename (g_get_user_data_dir (),
@@ -2214,6 +2165,7 @@ load_install_queue (GsPluginLoader *plugin_loader, GError **error)
/* add each app-id */
names = g_strsplit (contents, "\n", 0);
for (i = 0; names[i]; i++) {
+ _cleanup_object_unref_ GsApp *app = NULL;
if (strlen (names[i]) == 0)
continue;
app = gs_app_new (names[i]);
@@ -2232,7 +2184,6 @@ load_install_queue (GsPluginLoader *plugin_loader, GError **error)
g_debug ("adding pending app %s", gs_app_get_id (app));
gs_plugin_add_app (&list, app);
- g_object_unref (app);
}
/* refine */
@@ -2248,21 +2199,18 @@ load_install_queue (GsPluginLoader *plugin_loader, GError **error)
}
out:
gs_plugin_list_free (list);
- g_free (contents);
- g_strfreev (names);
- g_free (file);
return ret;
}
static void
save_install_queue (GsPluginLoader *plugin_loader)
{
- GError *error = NULL;
GPtrArray *pending_apps;
- GString *s;
gboolean ret;
- gchar *file;
gint i;
+ _cleanup_error_free_ GError *error = NULL;
+ _cleanup_string_free_ GString *s = NULL;
+ _cleanup_free_ gchar *file = NULL;
s = g_string_new ("");
pending_apps = plugin_loader->priv->pending_apps;
@@ -2284,13 +2232,8 @@ save_install_queue (GsPluginLoader *plugin_loader)
NULL);
g_debug ("saving install queue to %s", file);
ret = g_file_set_contents (file, s->str, s->len, &error);
- if (!ret) {
+ if (!ret)
g_warning ("failed to save install queue: %s", error->message);
- g_error_free (error);
- }
-
- g_free (file);
- g_string_free (s, TRUE);
}
static void
@@ -2363,7 +2306,7 @@ gs_plugin_loader_app_action_async (GsPluginLoader *plugin_loader,
gpointer user_data)
{
GsPluginLoaderAsyncState *state;
- GTask *task;
+ _cleanup_object_unref_ GTask *task = NULL;
g_return_if_fail (GS_IS_PLUGIN_LOADER (plugin_loader));
g_return_if_fail (GS_IS_APP (app));
@@ -2373,7 +2316,6 @@ gs_plugin_loader_app_action_async (GsPluginLoader *plugin_loader,
if (remove_app_from_install_queue (plugin_loader, app)) {
task = g_task_new (plugin_loader, cancellable, callback, user_data);
g_task_return_boolean (task, TRUE);
- g_object_unref (task);
return;
}
}
@@ -2383,7 +2325,6 @@ gs_plugin_loader_app_action_async (GsPluginLoader *plugin_loader,
add_app_to_install_queue (plugin_loader, app);
task = g_task_new (plugin_loader, cancellable, callback, user_data);
g_task_return_boolean (task, TRUE);
- g_object_unref (task);
return;
}
@@ -2417,7 +2358,6 @@ gs_plugin_loader_app_action_async (GsPluginLoader *plugin_loader,
g_task_set_task_data (task, state, (GDestroyNotify) gs_plugin_loader_free_async_state);
g_task_set_return_on_cancel (task, TRUE);
g_task_run_in_thread (task, gs_plugin_loader_app_action_thread_cb);
- g_object_unref (task);
}
/**
@@ -2480,13 +2420,13 @@ static void
gs_plugin_loader_run (GsPluginLoader *plugin_loader, const gchar *function_name)
{
gboolean ret;
- gchar *profile_id;
GsPluginFunc plugin_func = NULL;
GsPlugin *plugin;
guint i;
/* run each plugin */
for (i = 0; i < plugin_loader->priv->plugins->len; i++) {
+ _cleanup_free_ gchar *profile_id = NULL;
plugin = g_ptr_array_index (plugin_loader->priv->plugins, i);
ret = g_module_symbol (plugin->module,
function_name,
@@ -2499,7 +2439,6 @@ gs_plugin_loader_run (GsPluginLoader *plugin_loader, const gchar *function_name)
plugin_func (plugin);
gs_plugin_status_update (plugin, NULL, GS_PLUGIN_STATUS_FINISHED);
gs_profile_stop (plugin_loader->priv->profile, profile_id);
- g_free (profile_id);
}
}
@@ -2614,7 +2553,7 @@ gs_plugin_loader_open_plugin (GsPluginLoader *plugin_loader,
if (module == NULL) {
g_warning ("failed to open plugin %s: %s",
filename, g_module_error ());
- goto out;
+ return NULL;
}
/* get description */
@@ -2624,7 +2563,7 @@ gs_plugin_loader_open_plugin (GsPluginLoader *plugin_loader,
if (!ret) {
g_warning ("Plugin %s requires name", filename);
g_module_close (module);
- goto out;
+ return NULL;
}
/* get plugins this plugin depends on */
@@ -2650,7 +2589,6 @@ gs_plugin_loader_open_plugin (GsPluginLoader *plugin_loader,
/* add to array */
g_ptr_array_add (plugin_loader->priv->plugins, plugin);
-out:
return plugin;
}
@@ -2686,7 +2624,7 @@ gs_plugin_loader_get_scale (GsPluginLoader *plugin_loader)
void
gs_plugin_loader_set_location (GsPluginLoader *plugin_loader, const gchar *location)
{
- gchar *filename;
+ _cleanup_free_ gchar *filename = NULL;
g_free (plugin_loader->priv->location);
@@ -2699,7 +2637,6 @@ gs_plugin_loader_set_location (GsPluginLoader *plugin_loader, const gchar *locat
/* use the default, but this requires a 'make install' */
filename = g_strdup_printf ("gs-plugins-%s", GS_PLUGIN_API_VERSION);
plugin_loader->priv->location = g_build_filename (LIBDIR, filename, NULL);
- g_free (filename);
}
/**
@@ -2746,13 +2683,12 @@ gs_plugin_loader_setup (GsPluginLoader *plugin_loader, GError **error)
const gdouble dep_increment = 1.f;
gboolean changes;
gboolean ret = TRUE;
- gchar *filename_plugin;
- GDir *dir;
GsPlugin *dep;
GsPlugin *plugin;
guint dep_loop_check = 0;
guint i;
guint j;
+ _cleanup_dir_close_ GDir *dir = NULL;
g_return_val_if_fail (plugin_loader->priv->location != NULL, FALSE);
@@ -2767,6 +2703,7 @@ gs_plugin_loader_setup (GsPluginLoader *plugin_loader, GError **error)
/* try to open each plugin */
g_debug ("searching for plugins in %s", plugin_loader->priv->location);
do {
+ _cleanup_free_ gchar *filename_plugin = NULL;
filename_tmp = g_dir_read_name (dir);
if (filename_tmp == NULL)
break;
@@ -2776,7 +2713,6 @@ gs_plugin_loader_setup (GsPluginLoader *plugin_loader, GError **error)
filename_tmp,
NULL);
gs_plugin_loader_open_plugin (plugin_loader, filename_plugin);
- g_free (filename_plugin);
} while (TRUE);
/* order by deps */
@@ -2832,8 +2768,6 @@ gs_plugin_loader_setup (GsPluginLoader *plugin_loader, GError **error)
goto out;
out:
gs_profile_stop (plugin_loader->priv->profile, "GsPlugin::setup");
- if (dir != NULL)
- g_dir_close (dir);
return ret;
}
@@ -3001,10 +2935,10 @@ gs_plugin_loader_app_installed_cb (GObject *source,
GAsyncResult *res,
gpointer user_data)
{
- GError *error = NULL;
- GsApp *app = GS_APP (user_data);
GsPluginLoader *plugin_loader = GS_PLUGIN_LOADER (source);
gboolean ret;
+ _cleanup_error_free_ GError *error = NULL;
+ _cleanup_object_unref_ GsApp *app = GS_APP (user_data);
ret = gs_plugin_loader_app_action_finish (plugin_loader,
res,
@@ -3012,11 +2946,8 @@ gs_plugin_loader_app_installed_cb (GObject *source,
if (!ret) {
remove_app_from_install_queue (plugin_loader, app);
g_warning ("failed to install %s: %s",
- gs_app_get_id (app),
- error->message);
- g_error_free (error);
+ gs_app_get_id (app), error->message);
}
- g_object_unref (app);
}
/**
@@ -3076,9 +3007,9 @@ gs_plugin_loader_run_refresh_plugin (GsPluginLoader *plugin_loader,
const gchar *function_name = "gs_plugin_refresh";
gboolean exists;
gboolean ret = TRUE;
- gchar *profile_id = NULL;
GError *error_local = NULL;
GsPluginRefreshFunc plugin_func = NULL;
+ _cleanup_free_ gchar *profile_id = NULL;
exists = g_module_symbol (plugin->module,
function_name,
@@ -3108,7 +3039,6 @@ out:
gs_plugin_status_update (plugin, NULL, GS_PLUGIN_STATUS_FINISHED);
gs_profile_stop (plugin_loader->priv->profile, profile_id);
}
- g_free (profile_id);
return ret;
}
@@ -3123,7 +3053,7 @@ gs_plugin_loader_run_refresh (GsPluginLoader *plugin_loader,
GError **error)
{
gboolean anything_ran = FALSE;
- gboolean ret = TRUE;
+ gboolean ret;
GsPlugin *plugin;
guint i;
@@ -3132,11 +3062,8 @@ gs_plugin_loader_run_refresh (GsPluginLoader *plugin_loader,
plugin = g_ptr_array_index (plugin_loader->priv->plugins, i);
if (!plugin->enabled)
continue;
- ret = g_cancellable_set_error_if_cancelled (cancellable, error);
- if (ret) {
- ret = FALSE;
- goto out;
- }
+ if (g_cancellable_set_error_if_cancelled (cancellable, error))
+ return FALSE;
ret = gs_plugin_loader_run_refresh_plugin (plugin_loader,
plugin,
cache_age,
@@ -3144,20 +3071,18 @@ gs_plugin_loader_run_refresh (GsPluginLoader *plugin_loader,
cancellable,
error);
if (!ret)
- goto out;
+ return FALSE;
anything_ran = TRUE;
}
/* nothing ran */
if (!anything_ran) {
- ret = FALSE;
g_set_error (error,
GS_PLUGIN_LOADER_ERROR,
GS_PLUGIN_LOADER_ERROR_FAILED,
"no plugin could handle refresh");
- goto out;
+ return FALSE;
}
-out:
return ret;
}
@@ -3176,19 +3101,17 @@ gs_plugin_loader_refresh_thread_cb (GTask *task,
gboolean ret;
ret = gs_plugin_loader_run_refresh (plugin_loader,
- state->cache_age,
- state->flags,
- cancellable,
- &error);
+ state->cache_age,
+ state->flags,
+ cancellable,
+ &error);
if (!ret) {
g_task_return_error (task, error);
- goto out;
+ return;
}
/* success */
g_task_return_boolean (task, TRUE);
-out:
- return;
}
/**
@@ -3206,7 +3129,7 @@ gs_plugin_loader_refresh_async (GsPluginLoader *plugin_loader,
gpointer user_data)
{
GsPluginLoaderAsyncState *state;
- GTask *task;
+ _cleanup_object_unref_ GTask *task = NULL;
g_return_if_fail (GS_IS_PLUGIN_LOADER (plugin_loader));
g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
@@ -3221,7 +3144,6 @@ gs_plugin_loader_refresh_async (GsPluginLoader *plugin_loader,
g_task_set_task_data (task, state, (GDestroyNotify) gs_plugin_loader_free_async_state);
g_task_set_return_on_cancel (task, TRUE);
g_task_run_in_thread (task, gs_plugin_loader_refresh_thread_cb);
- g_object_unref (task);
}
/**
@@ -3255,13 +3177,13 @@ 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 = NULL;
GError *error = NULL;
GsPluginLoaderAsyncState *state = (GsPluginLoaderAsyncState *) task_data;
GsPluginLoader *plugin_loader = GS_PLUGIN_LOADER (object);
GsPlugin *plugin;
GsPluginFilenameToAppFunc plugin_func = NULL;
guint i;
+ _cleanup_free_ gchar *profile_id = NULL;
/* run each plugin */
for (i = 0; i < plugin_loader->priv->plugins->len; i++) {
@@ -3308,28 +3230,25 @@ gs_plugin_loader_filename_to_app_thread_cb (GTask *task,
gs_plugin_list_filter_duplicates (&state->list);
if (state->list == NULL) {
g_task_return_new_error (task,
- GS_PLUGIN_LOADER_ERROR,
- GS_PLUGIN_LOADER_ERROR_NO_RESULTS,
- "no filename_to_app results to show");
+ GS_PLUGIN_LOADER_ERROR,
+ GS_PLUGIN_LOADER_ERROR_NO_RESULTS,
+ "no filename_to_app results to show");
goto out;
}
/* success */
if (g_list_length (state->list) != 1) {
g_task_return_new_error (task,
- GS_PLUGIN_LOADER_ERROR,
- GS_PLUGIN_LOADER_ERROR_NO_RESULTS,
- "no application was created for %s",
- state->filename);
+ GS_PLUGIN_LOADER_ERROR,
+ GS_PLUGIN_LOADER_ERROR_NO_RESULTS,
+ "no application was created for %s",
+ state->filename);
goto out;
}
g_task_return_pointer (task, g_object_ref (state->list->data), (GDestroyNotify) g_object_unref);
out:
- if (profile_id != NULL) {
+ if (profile_id != NULL)
gs_profile_stop (plugin_loader->priv->profile, profile_id);
- g_free (profile_id);
- }
- return;
}
/**
@@ -3353,7 +3272,7 @@ gs_plugin_loader_filename_to_app_async (GsPluginLoader *plugin_loader,
gpointer user_data)
{
GsPluginLoaderAsyncState *state;
- GTask *task;
+ _cleanup_object_unref_ GTask *task = NULL;
g_return_if_fail (GS_IS_PLUGIN_LOADER (plugin_loader));
g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
@@ -3368,7 +3287,6 @@ gs_plugin_loader_filename_to_app_async (GsPluginLoader *plugin_loader,
g_task_set_task_data (task, state, (GDestroyNotify) gs_plugin_loader_free_async_state);
g_task_set_return_on_cancel (task, TRUE);
g_task_run_in_thread (task, gs_plugin_loader_filename_to_app_thread_cb);
- g_object_unref (task);
}
/**
diff --git a/src/gs-plugin.c b/src/gs-plugin.c
index d7411e5..5738e99 100644
--- a/src/gs-plugin.c
+++ b/src/gs-plugin.c
@@ -23,6 +23,7 @@
#include <glib.h>
+#include "gs-cleanup.h"
#include "gs-plugin.h"
#define GS_PLUGIN_OS_RELEASE_FN "/etc/os-release"
@@ -65,30 +66,21 @@ gs_plugin_set_enabled (GsPlugin *plugin, gboolean enabled)
gboolean
gs_plugin_check_distro_id (GsPlugin *plugin, const gchar *distro_id)
{
- GError *error = NULL;
- gboolean ret;
- gchar *data = NULL;
- gchar *search = NULL;
+ _cleanup_error_free_ GError *error = NULL;
+ _cleanup_free_ gchar *data = NULL;
+ _cleanup_free_ gchar *search = NULL;
/* check that we are running on Fedora */
- ret = g_file_get_contents (GS_PLUGIN_OS_RELEASE_FN,
- &data, NULL, &error);
- if (!ret) {
+ if (!g_file_get_contents (GS_PLUGIN_OS_RELEASE_FN, &data, NULL, &error)) {
g_warning ("%s could not be read: %s",
GS_PLUGIN_OS_RELEASE_FN,
error->message);
- g_error_free (error);
- goto out;
+ return FALSE;
}
search = g_strdup_printf ("ID=%s\n", distro_id);
- if (g_strstr_len (data, -1, search) == NULL) {
- ret = FALSE;
- goto out;
- }
-out:
- g_free (data);
- g_free (search);
- return ret;
+ if (g_strstr_len (data, -1, search) == NULL)
+ return FALSE;
+ return TRUE;
}
/**
@@ -146,12 +138,11 @@ gs_plugin_list_randomize_cb (gconstpointer a, gconstpointer b, gpointer user_dat
{
const gchar *k1;
const gchar *k2;
- gchar *key;
+ _cleanup_free_ gchar *key = NULL;
key = g_strdup_printf ("Plugin::sort-key[%p]", user_data);
k1 = gs_app_get_metadata_item (GS_APP (a), key);
k2 = gs_app_get_metadata_item (GS_APP (b), key);
- g_free (key);
return g_strcmp0 (k1, k2);
}
@@ -167,8 +158,8 @@ gs_plugin_list_randomize (GList **list)
GList *l;
GRand *rand;
GsApp *app;
- gchar *key;
gchar sort_key[] = { '\0', '\0', '\0', '\0' };
+ _cleanup_free_ gchar *key = NULL;
key = g_strdup_printf ("Plugin::sort-key[%p]", list);
rand = g_rand_new ();
@@ -186,7 +177,6 @@ gs_plugin_list_randomize (GList **list)
app = GS_APP (l->data);
gs_app_set_metadata (app, key, NULL);
}
- g_free (key);
g_rand_free (rand);
g_date_time_unref (date);
}
@@ -197,12 +187,12 @@ gs_plugin_list_randomize (GList **list)
void
gs_plugin_list_filter_duplicates (GList **list)
{
- GHashTable *hash;
GList *l;
GList *new = NULL;
GsApp *app;
GsApp *found;
const gchar *id;
+ _cleanup_hashtable_unref_ GHashTable *hash = NULL;
g_return_if_fail (list != NULL);
@@ -224,7 +214,6 @@ gs_plugin_list_filter_duplicates (GList **list)
}
g_debug ("ignoring duplicate %s", id);
}
- g_hash_table_unref (hash);
/* replace the list */
gs_plugin_list_free (*list);
diff --git a/src/gs-popular-tile.c b/src/gs-popular-tile.c
index d86a469..8a41b08 100644
--- a/src/gs-popular-tile.c
+++ b/src/gs-popular-tile.c
@@ -24,6 +24,7 @@
#include <glib/gi18n.h>
#include <gtk/gtk.h>
+#include "gs-cleanup.h"
#include "gs-popular-tile.h"
#include "gs-star-widget.h"
#include "gs-utils.h"
@@ -59,7 +60,7 @@ app_state_changed_idle (gpointer user_data)
GsPopularTilePrivate *priv;
GtkWidget *label;
gboolean installed;
- gchar *name;
+ _cleanup_free_ gchar *name = NULL;
priv = gs_popular_tile_get_instance_private (tile);
accessible = gtk_widget_get_accessible (GTK_WIDGET (tile));
@@ -100,7 +101,6 @@ app_state_changed_idle (gpointer user_data)
atk_object_set_name (accessible, name);
atk_object_set_description (accessible, gs_app_get_summary (priv->app));
}
- g_free (name);
g_object_unref (tile);
return G_SOURCE_REMOVE;
@@ -132,12 +132,12 @@ gs_popular_tile_set_app (GsPopularTile *tile, GsApp *app)
if (gs_app_get_rating_kind (priv->app) == GS_APP_RATING_KIND_USER) {
gs_star_widget_set_rating (GS_STAR_WIDGET (priv->stars),
- GS_APP_RATING_KIND_USER,
- gs_app_get_rating (priv->app));
+ GS_APP_RATING_KIND_USER,
+ gs_app_get_rating (priv->app));
} else {
gs_star_widget_set_rating (GS_STAR_WIDGET (priv->stars),
- GS_APP_RATING_KIND_KUDOS,
- gs_app_get_kudos_percentage (priv->app));
+ GS_APP_RATING_KIND_KUDOS,
+ gs_app_get_kudos_percentage (priv->app));
}
gtk_stack_set_visible_child_name (GTK_STACK (priv->stack), "content");
diff --git a/src/gs-profile.c b/src/gs-profile.c
index 5f43fe6..859197b 100644
--- a/src/gs-profile.c
+++ b/src/gs-profile.c
@@ -23,6 +23,7 @@
#include <glib/gi18n.h>
+#include "gs-cleanup.h"
#include "gs-profile.h"
static void gs_profile_finalize (GObject *object);
@@ -82,7 +83,7 @@ gs_profile_start (GsProfile *profile, const gchar *id)
{
GThread *self;
GsProfileItem *item;
- gchar *id_thr;
+ _cleanup_free_ gchar *id_thr = NULL;
g_return_if_fail (GS_IS_PROFILE (profile));
g_return_if_fail (id != NULL);
@@ -115,7 +116,6 @@ gs_profile_start (GsProfile *profile, const gchar *id)
out:
/* unlock */
g_mutex_unlock (&profile->priv->mutex);
- g_free (id_thr);
}
/**
@@ -126,8 +126,8 @@ gs_profile_stop (GsProfile *profile, const gchar *id)
{
GThread *self;
GsProfileItem *item;
- gchar *id_thr;
gdouble elapsed_ms;
+ _cleanup_free_ gchar *id_thr = NULL;
g_return_if_fail (GS_IS_PROFILE (profile));
g_return_if_fail (id != NULL);
@@ -164,7 +164,6 @@ gs_profile_stop (GsProfile *profile, const gchar *id)
out:
/* unlock */
g_mutex_unlock (&profile->priv->mutex);
- g_free (id_thr);
}
/**
diff --git a/src/gs-proxy-settings.c b/src/gs-proxy-settings.c
index 494ad2f..d5e5bec 100644
--- a/src/gs-proxy-settings.c
+++ b/src/gs-proxy-settings.c
@@ -26,6 +26,7 @@
#include <packagekit-glib2/packagekit.h>
#include <gsettings-desktop-schemas/gdesktop-enums.h>
+#include "gs-cleanup.h"
#include "gs-proxy-settings.h"
struct _GsProxySettings {
@@ -48,21 +49,20 @@ static gchar *
get_proxy_http (GsProxySettings *proxy_settings)
{
gboolean ret;
- gchar *host = NULL;
- gchar *password = NULL;
- gchar *proxy = NULL;
- gchar *username = NULL;
GString *string = NULL;
guint port;
GDesktopProxyMode proxy_mode;
+ _cleanup_free_ gchar *host = NULL;
+ _cleanup_free_ gchar *password = NULL;
+ _cleanup_free_ gchar *username = NULL;
proxy_mode = g_settings_get_enum (proxy_settings->settings, "mode");
if (proxy_mode != G_DESKTOP_PROXY_MODE_MANUAL)
- goto out;
+ return NULL;
host = g_settings_get_string (proxy_settings->settings_http, "host");
if (host == NULL)
- goto out;
+ return NULL;
port = g_settings_get_int (proxy_settings->settings_http, "port");
@@ -70,10 +70,10 @@ get_proxy_http (GsProxySettings *proxy_settings)
"use-authentication");
if (ret) {
username = g_settings_get_string (proxy_settings->settings_http,
- "authentication-user");
+ "authentication-user");
password = g_settings_get_string (proxy_settings->settings_http,
"authentication-password");
- }
+ }
/* make PackageKit proxy string */
string = g_string_new (host);
@@ -85,67 +85,50 @@ get_proxy_http (GsProxySettings *proxy_settings)
g_string_append_printf (string, "@%s", username);
else if (password != NULL)
g_string_append_printf (string, "@:%s", password);
- proxy = g_string_free (string, FALSE);
-
-out:
- g_free (host);
- g_free (username);
- g_free (password);
-
- return proxy;
+ return g_string_free (string, FALSE);
}
static gchar *
get_proxy_ftp (GsProxySettings *proxy_settings)
{
- gchar *host = NULL;
- gchar *proxy = NULL;
GString *string = NULL;
guint port;
GDesktopProxyMode proxy_mode;
+ _cleanup_free_ gchar *host = NULL;
proxy_mode = g_settings_get_enum (proxy_settings->settings, "mode");
if (proxy_mode != G_DESKTOP_PROXY_MODE_MANUAL)
- goto out;
+ return NULL;
host = g_settings_get_string (proxy_settings->settings_ftp, "host");
if (host == NULL)
- goto out;
+ return NULL;
port = g_settings_get_int (proxy_settings->settings_ftp, "port");
if (port == 0)
- goto out;
+ return NULL;
/* make PackageKit proxy string */
string = g_string_new (host);
if (port > 0)
g_string_append_printf (string, ":%i", port);
- proxy = g_string_free (string, FALSE);
-
-out:
- g_free (host);
-
- return proxy;
+ return g_string_free (string, FALSE);
}
static void
set_proxy_cb (GObject *object, GAsyncResult *res, gpointer user_data)
{
- gboolean ret;
- GError *error = NULL;
-
- ret = pk_control_set_proxy_finish (PK_CONTROL (object), res, &error);
- if (!ret) {
+ _cleanup_error_free_ GError *error = NULL;
+ if (!pk_control_set_proxy_finish (PK_CONTROL (object), res, &error)) {
if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
g_warning ("failed to set proxies: %s", error->message);
- g_error_free (error);
}
}
static void
reload_proxy_settings (GsProxySettings *proxy_settings)
{
- gchar *proxy_http;
- gchar *proxy_ftp;
+ _cleanup_free_ gchar *proxy_http = NULL;
+ _cleanup_free_ gchar *proxy_ftp = NULL;
proxy_http = get_proxy_http (proxy_settings);
proxy_ftp = get_proxy_ftp (proxy_settings);
@@ -158,8 +141,6 @@ reload_proxy_settings (GsProxySettings *proxy_settings)
proxy_settings->cancellable,
set_proxy_cb,
proxy_settings);
- g_free (proxy_http);
- g_free (proxy_ftp);
}
static void
diff --git a/src/gs-screenshot-image.c b/src/gs-screenshot-image.c
index a96b993..028549d 100644
--- a/src/gs-screenshot-image.c
+++ b/src/gs-screenshot-image.c
@@ -29,6 +29,7 @@
#include <libgnome-desktop/gnome-bg.h>
#include <libgnome-desktop/gnome-desktop-thumbnail.h>
+#include "gs-cleanup.h"
#include "gs-screenshot-image.h"
#include "gs-utils.h"
@@ -89,11 +90,10 @@ gs_screenshot_image_set_error (GsScreenshotImage *ssimg, const gchar *message)
static GdkPixbuf *
gs_screenshot_image_get_desktop_pixbuf (GsScreenshotImage *ssimg)
{
- GdkPixbuf *pixbuf;
- GnomeBG *bg;
- GnomeDesktopThumbnailFactory *factory;
- GSettings *settings;
GsScreenshotImagePrivate *priv;
+ _cleanup_object_unref_ GnomeBG *bg = NULL;
+ _cleanup_object_unref_ GnomeDesktopThumbnailFactory *factory = NULL;
+ _cleanup_object_unref_ GSettings *settings = NULL;
priv = gs_screenshot_image_get_instance_private (ssimg);
@@ -101,11 +101,9 @@ gs_screenshot_image_get_desktop_pixbuf (GsScreenshotImage *ssimg)
bg = gnome_bg_new ();
settings = g_settings_new ("org.gnome.desktop.background");
gnome_bg_load_from_preferences (bg, settings);
- pixbuf = gnome_bg_create_thumbnail (bg, factory, gdk_screen_get_default (), priv->width,
priv->height);
- g_object_unref (bg);
- g_object_unref (factory);
- g_object_unref (settings);
- return pixbuf;
+ return gnome_bg_create_thumbnail (bg, factory,
+ gdk_screen_get_default (),
+ priv->width, priv->height);
}
/**
@@ -114,8 +112,7 @@ gs_screenshot_image_get_desktop_pixbuf (GsScreenshotImage *ssimg)
static gboolean
gs_screenshot_image_use_desktop_background (GdkPixbuf *pixbuf)
{
- AsImage *im;
- gboolean ret;
+ _cleanup_object_unref_ AsImage *im = NULL;
/* nothing to show, means no background mode */
if (pixbuf == NULL)
@@ -124,9 +121,7 @@ gs_screenshot_image_use_desktop_background (GdkPixbuf *pixbuf)
/* use a temp AsImage */
im = as_image_new ();
as_image_set_pixbuf (im, pixbuf);
- ret = (as_image_get_alpha_flags (im) & AS_IMAGE_ALPHA_FLAG_INTERNAL) > 0;
- g_object_unref (im);
- return ret;
+ return (as_image_get_alpha_flags (im) & AS_IMAGE_ALPHA_FLAG_INTERNAL) > 0;
}
/**
@@ -135,9 +130,9 @@ gs_screenshot_image_use_desktop_background (GdkPixbuf *pixbuf)
static void
as_screenshot_show_image (GsScreenshotImage *ssimg)
{
- GdkPixbuf *pixbuf_bg = NULL;
- GdkPixbuf *pixbuf = NULL;
GsScreenshotImagePrivate *priv;
+ _cleanup_object_unref_ GdkPixbuf *pixbuf_bg = NULL;
+ _cleanup_object_unref_ GdkPixbuf *pixbuf = NULL;
priv = gs_screenshot_image_get_instance_private (ssimg);
@@ -185,10 +180,6 @@ as_screenshot_show_image (GsScreenshotImage *ssimg)
priv->current_image = "image1";
}
- if (pixbuf != NULL)
- g_object_unref (pixbuf);
- if (pixbuf_bg != NULL)
- g_object_unref (pixbuf_bg);
gtk_widget_show (GTK_WIDGET (ssimg));
}
@@ -199,24 +190,22 @@ static void
gs_screenshot_image_show_blurred (GsScreenshotImage *ssimg,
const gchar *filename_thumb)
{
- AsImage *im;
- GdkPixbuf *pb = NULL;
GsScreenshotImagePrivate *priv;
- gboolean ret;
+ _cleanup_object_unref_ AsImage *im = NULL;
+ _cleanup_object_unref_ GdkPixbuf *pb = NULL;
priv = gs_screenshot_image_get_instance_private (ssimg);
/* create an helper which can do the blurring for us */
im = as_image_new ();
- ret = as_image_load_filename (im, filename_thumb, NULL);
- if (!ret)
- goto out;
+ if (!as_image_load_filename (im, filename_thumb, NULL))
+ return;
pb = as_image_save_pixbuf (im,
priv->width * priv->scale,
priv->height * priv->scale,
AS_IMAGE_SAVE_FLAG_BLUR);
if (pb == NULL)
- goto out;
+ return;
if (g_strcmp0 (priv->current_image, "image1") == 0) {
gs_image_set_from_pixbuf_with_scale (GTK_IMAGE (priv->image1),
@@ -225,11 +214,6 @@ gs_screenshot_image_show_blurred (GsScreenshotImage *ssimg,
gs_image_set_from_pixbuf_with_scale (GTK_IMAGE (priv->image2),
pb, priv->scale);
}
-out:
- if (im != NULL)
- g_object_unref (im);
- if (pb != NULL)
- g_object_unref (pb);
}
/**
@@ -240,20 +224,20 @@ gs_screenshot_image_complete_cb (SoupSession *session,
SoupMessage *msg,
gpointer user_data)
{
- AsImage *im = NULL;
GsScreenshotImagePrivate *priv;
- GsScreenshotImage *ssimg = GS_SCREENSHOT_IMAGE (user_data);
- GError *error = NULL;
- GdkPixbuf *pixbuf = NULL;
- GInputStream *stream = NULL;
gboolean ret;
+ _cleanup_error_free_ GError *error = NULL;
+ _cleanup_object_unref_ AsImage *im = NULL;
+ _cleanup_object_unref_ GdkPixbuf *pixbuf = NULL;
+ _cleanup_object_unref_ GInputStream *stream = NULL;
+ _cleanup_object_unref_ GsScreenshotImage *ssimg = GS_SCREENSHOT_IMAGE (user_data);
if (msg->status_code != SOUP_STATUS_OK) {
/* TRANSLATORS: this is when we try to download a screenshot and
* we get back 404 */
gs_screenshot_image_set_error (ssimg, _("Screenshot not found"));
gtk_widget_hide (GTK_WIDGET (ssimg));
- goto out;
+ return;
}
priv = gs_screenshot_image_get_instance_private (ssimg);
@@ -263,14 +247,14 @@ gs_screenshot_image_complete_cb (SoupSession *session,
msg->response_body->length,
NULL);
if (stream == NULL)
- goto out;
+ return;
/* load the image */
pixbuf = gdk_pixbuf_new_from_stream (stream, NULL, NULL);
if (pixbuf == NULL) {
/* TRANSLATORS: possibly image file corrupt or not an image */
gs_screenshot_image_set_error (ssimg, _("Failed to load image"));
- goto out;
+ return;
}
/* is image size destination size unknown or exactly the correct size */
@@ -283,8 +267,7 @@ gs_screenshot_image_complete_cb (SoupSession *session,
&error);
if (!ret) {
gs_screenshot_image_set_error (ssimg, error->message);
- g_error_free (error);
- goto out;
+ return;
}
} else {
/* save to file, using the same code as the AppStream builder
@@ -296,21 +279,12 @@ gs_screenshot_image_complete_cb (SoupSession *session,
AS_IMAGE_SAVE_FLAG_PAD_16_9, &error);
if (!ret) {
gs_screenshot_image_set_error (ssimg, error->message);
- g_error_free (error);
- goto out;
+ return;
}
}
/* got image, so show */
as_screenshot_show_image (ssimg);
-out:
- if (stream != NULL)
- g_object_unref (stream);
- if (pixbuf != NULL)
- g_object_unref (pixbuf);
- if (im != NULL)
- g_object_unref (im);
- g_object_unref (ssimg);
}
/**
@@ -377,11 +351,11 @@ gs_screenshot_image_load_async (GsScreenshotImage *ssimg,
SoupMessage *msg = NULL;
SoupURI *base_uri = NULL;
const gchar *url;
- gchar *basename = NULL;
- gchar *cachedir = NULL;
- gchar *cachedir2 = NULL;
- gchar *sizedir = NULL;
gint rc;
+ _cleanup_free_ gchar *basename = NULL;
+ _cleanup_free_ gchar *cachedir2 = NULL;
+ _cleanup_free_ gchar *cachedir = NULL;
+ _cleanup_free_ gchar *sizedir = NULL;
g_return_if_fail (GS_IS_SCREENSHOT_IMAGE (ssimg));
@@ -411,7 +385,7 @@ gs_screenshot_image_load_async (GsScreenshotImage *ssimg,
/* TRANSLATORS: this is when we request a screenshot size that
* the generator did not create or the parser did not add */
gs_screenshot_image_set_error (ssimg, _("Screenshot size not found"));
- goto out;
+ return;
}
url = as_image_get_url (im);
basename = g_path_get_basename (url);
@@ -430,14 +404,14 @@ gs_screenshot_image_load_async (GsScreenshotImage *ssimg,
/* TRANSLATORS: this is when we try create the cache directory
* but we were out of space or permission was denied */
gs_screenshot_image_set_error (ssimg, _("Could not create cache"));
- goto out;
+ return;
}
/* does local file already exist */
priv->filename = g_build_filename (cachedir, basename, NULL);
if (g_file_test (priv->filename, G_FILE_TEST_EXISTS)) {
as_screenshot_show_image (ssimg);
- goto out;
+ return;
}
/* can we load a blurred smaller version of this straight away */
@@ -460,26 +434,22 @@ gs_screenshot_image_load_async (GsScreenshotImage *ssimg,
/* TRANSLATORS: this is when we try to download a screenshot
* that was not a valid URL */
gs_screenshot_image_set_error (ssimg, _("Screenshot not valid"));
- goto out;
+ soup_uri_free (base_uri);
+ return;
}
msg = soup_message_new_from_uri (SOUP_METHOD_GET, base_uri);
if (msg == NULL) {
/* TRANSLATORS: this is when networking is not available */
gs_screenshot_image_set_error (ssimg, _("Screenshot not available"));
- goto out;
+ soup_uri_free (base_uri);
+ return;
}
/* send async */
soup_session_queue_message (priv->session, msg,
gs_screenshot_image_complete_cb,
g_object_ref (ssimg));
-out:
- g_free (basename);
- g_free (sizedir);
- g_free (cachedir);
- g_free (cachedir2);
- if (base_uri != NULL)
- soup_uri_free (base_uri);
+ soup_uri_free (base_uri);
}
/**
diff --git a/src/gs-self-test.c b/src/gs-self-test.c
index 1d188ba..58ba650 100644
--- a/src/gs-self-test.c
+++ b/src/gs-self-test.c
@@ -27,6 +27,7 @@
#include <glib/gstdio.h>
#include "gs-app.h"
+#include "gs-cleanup.h"
#include "gs-markdown.h"
#include "gs-plugin.h"
#include "gs-plugin-loader.h"
@@ -36,10 +37,10 @@
static void
gs_markdown_func (void)
{
- GsMarkdown *md;
gchar *text;
const gchar *markdown;
const gchar *markdown_expected;
+ _cleanup_object_unref_ GsMarkdown *md = NULL;
/* get GsMarkdown object */
md = gs_markdown_new (GS_MARKDOWN_OUTPUT_PANGO);
@@ -211,8 +212,6 @@ gs_markdown_func (void)
text = gs_markdown_parse (md, markdown);
g_assert_cmpstr (text, ==, markdown_expected);
g_free (text);
-
- g_object_unref (md);
}
static gboolean
@@ -277,23 +276,20 @@ gs_plugin_func (void)
static void
gs_app_subsume_func (void)
{
- GsApp *new;
- GsApp *old;
+ _cleanup_object_unref_ GsApp *new = NULL;
+ _cleanup_object_unref_ GsApp *old = NULL;
new = gs_app_new ("xxx.desktop");
old = gs_app_new ("yyy.desktop");
gs_app_set_metadata (old, "foo", "bar");
gs_app_subsume (new, old);
g_assert_cmpstr (gs_app_get_metadata_item (new, "foo"), ==, "bar");
-
- g_object_unref (new);
- g_object_unref (old);
}
static void
gs_app_func (void)
{
- GsApp *app;
+ _cleanup_object_unref_ GsApp *app = NULL;
app = gs_app_new ("gnome-software");
g_assert (GS_IS_APP (app));
@@ -316,8 +312,6 @@ gs_app_func (void)
g_assert_cmpstr (gs_app_get_name (app), ==, "dave");
gs_app_set_name (app, GS_APP_QUALITY_HIGHEST, "hugh");
g_assert_cmpstr (gs_app_get_name (app), ==, "hugh");
-
- g_object_unref (app);
}
static guint _status_changed_cnt = 0;
@@ -334,9 +328,9 @@ gs_plugin_loader_status_changed_cb (GsPluginLoader *plugin_loader,
static void
gs_plugin_loader_dedupe_func (void)
{
- GsApp *app1;
- GsApp *app2;
- GsPluginLoader *loader;
+ _cleanup_object_unref_ GsApp *app1 = NULL;
+ _cleanup_object_unref_ GsApp *app2 = NULL;
+ _cleanup_object_unref_ GsPluginLoader *loader = NULL;
loader = gs_plugin_loader_new ();
@@ -354,11 +348,6 @@ gs_plugin_loader_dedupe_func (void)
app2 = gs_plugin_loader_dedupe (loader, app2);
g_assert_cmpstr (gs_app_get_id (app2), ==, "app1");
g_assert_cmpstr (gs_app_get_description (app2), ==, "description");
-
- g_object_unref (app1);
- g_object_unref (app2);
-
- g_object_unref (loader);
}
static void
@@ -369,7 +358,7 @@ gs_plugin_loader_func (void)
GList *list;
GList *l;
GsApp *app;
- GsPluginLoader *loader;
+ _cleanup_object_unref_ GsPluginLoader *loader = NULL;
/* not avaiable in make distcheck */
if (!g_file_test (GS_MODULESETDIR, G_FILE_TEST_EXISTS))
@@ -501,18 +490,16 @@ gs_plugin_loader_func (void)
g_assert (ret);
g_assert_cmpint (gs_app_get_rating (app), ==, 35);
g_object_unref (app);
-
- g_object_unref (loader);
}
static void
gs_plugin_loader_refine_func (void)
{
GError *error = NULL;
- GsApp *app;
- GsPluginLoader *loader;
const gchar *url;
gboolean ret;
+ _cleanup_object_unref_ GsApp *app = NULL;
+ _cleanup_object_unref_ GsPluginLoader *loader = NULL;
/* not avaiable in make distcheck */
if (!g_file_test (GS_MODULESETDIR, G_FILE_TEST_EXISTS))
@@ -546,9 +533,6 @@ gs_plugin_loader_refine_func (void)
g_assert_cmpstr (gs_app_get_description (app), !=, NULL);
url = gs_app_get_url (app, AS_URL_KIND_HOMEPAGE);
g_assert_cmpstr (url, ==, "http://www.gimp.org/");
-
- g_object_unref (app);
- g_object_unref (loader);
}
static void
@@ -563,8 +547,8 @@ gs_plugin_loader_empty_func (void)
GList *subcats;
GsCategory *category;
GsCategory *sub;
- GsPluginLoader *loader;
guint empty_subcats_cnt = 0;
+ _cleanup_object_unref_ GsPluginLoader *loader = NULL;
/* not avaiable in make distcheck */
if (!g_file_test (GS_MODULESETDIR, G_FILE_TEST_EXISTS))
@@ -639,17 +623,16 @@ gs_plugin_loader_empty_func (void)
g_assert_cmpint (empty_subcats_cnt, ==, 0);
gs_plugin_list_free (list);
- g_object_unref (loader);
}
static void
gs_plugin_loader_webapps_func (void)
{
- GsPluginLoader *loader;
- GsApp *app;
- gchar *path;
gboolean ret;
GError *error = NULL;
+ _cleanup_free_ gchar *path = NULL;
+ _cleanup_object_unref_ GsApp *app = NULL;
+ _cleanup_object_unref_ GsPluginLoader *loader = NULL;
/* not avaiable in make distcheck */
if (!g_file_test (GS_MODULESETDIR, G_FILE_TEST_EXISTS))
@@ -696,9 +679,6 @@ gs_plugin_loader_webapps_func (void)
g_assert_cmpint (gs_app_get_state (app), ==, AS_APP_STATE_UNAVAILABLE);
g_unlink (path);
- g_free (path);
- g_object_unref (app);
- g_object_unref (loader);
}
int
diff --git a/src/gs-shell-category.c b/src/gs-shell-category.c
index e332610..e6af9a5 100644
--- a/src/gs-shell-category.c
+++ b/src/gs-shell-category.c
@@ -25,6 +25,7 @@
#include <string.h>
#include <glib/gi18n.h>
+#include "gs-cleanup.h"
#include "gs-utils.h"
#include "gs-app-tile.h"
#include "gs-shell-category.h"
@@ -87,7 +88,6 @@ gs_shell_category_get_apps_cb (GObject *source_object,
GAsyncResult *res,
gpointer user_data)
{
- GError *error = NULL;
gint i = 0;
GList *l;
GList *list;
@@ -96,15 +96,14 @@ gs_shell_category_get_apps_cb (GObject *source_object,
GsShellCategory *shell = GS_SHELL_CATEGORY (user_data);
GsShellCategoryPrivate *priv = shell->priv;
GsPluginLoader *plugin_loader = GS_PLUGIN_LOADER (source_object);
+ _cleanup_error_free_ GError *error = NULL;
list = gs_plugin_loader_get_category_apps_finish (plugin_loader,
res,
&error);
if (list == NULL) {
- if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
+ if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
g_warning ("failed to get apps for category apps: %s", error->message);
- }
- g_error_free (error);
goto out;
}
gtk_grid_remove_column (GTK_GRID (priv->category_detail_grid), 1);
@@ -186,7 +185,9 @@ filter_selected (GtkListBox *filters, GtkListBoxRow *row, gpointer data)
}
static void
-gs_shell_category_create_filter_list (GsShellCategory *shell, GsCategory *category, GsCategory *subcategory)
+gs_shell_category_create_filter_list (GsShellCategory *shell,
+ GsCategory *category,
+ GsCategory *subcategory)
{
GsShellCategoryPrivate *priv = shell->priv;
GtkWidget *row;
@@ -368,9 +369,7 @@ GsShellCategory *
gs_shell_category_new (void)
{
GsShellCategory *shell;
-
shell = g_object_new (GS_TYPE_SHELL_CATEGORY, NULL);
-
return shell;
}
diff --git a/src/gs-shell-details.c b/src/gs-shell-details.c
index 9657e11..4dcd421 100644
--- a/src/gs-shell-details.c
+++ b/src/gs-shell-details.c
@@ -29,6 +29,7 @@
#include "gs-utils.h"
+#include "gs-cleanup.h"
#include "gs-shell-details.h"
#include "gs-app-addon-row.h"
#include "gs-history-dialog.h"
@@ -316,14 +317,13 @@ gs_shell_details_screenshot_selected_cb (GtkListBox *list,
GsScreenshotImage *ssmain;
GsScreenshotImage *ssthumb;
AsScreenshot *ss;
- GList *children;
+ _cleanup_list_free_ GList *children = NULL;
if (row == NULL)
return;
children = gtk_container_get_children (GTK_CONTAINER (priv->box_details_screenshot_main));
ssmain = GS_SCREENSHOT_IMAGE (children->data);
- g_list_free (children);
ssthumb = GS_SCREENSHOT_IMAGE (gtk_bin_get_child (GTK_BIN (row)));
ss = gs_screenshot_image_get_screenshot (ssthumb);
@@ -446,17 +446,13 @@ gs_shell_details_refresh_screenshots (GsShellDetails *shell_details)
static void
gs_shell_details_website_cb (GtkWidget *widget, GsShellDetails *shell_details)
{
- GError *error = NULL;
GsShellDetailsPrivate *priv = shell_details->priv;
const gchar *url;
- gboolean ret;
+ _cleanup_error_free_ GError *error = NULL;
url = gs_app_get_url (priv->app, AS_URL_KIND_HOMEPAGE);
- ret = gtk_show_uri (NULL, url, GDK_CURRENT_TIME, &error);
- if (!ret) {
- g_warning ("spawn of '%s' failed", url);
- g_error_free (error);
- }
+ if (!gtk_show_uri (NULL, url, GDK_CURRENT_TIME, &error))
+ g_warning ("spawn of '%s' failed: %s", url, error->message);
}
/**
@@ -468,13 +464,13 @@ gs_shell_details_set_description (GsShellDetails *shell_details, const gchar *tm
GsShellDetailsPrivate *priv = shell_details->priv;
GtkStyleContext *style_context;
GtkWidget *para;
- gchar **split = NULL;
guint i;
+ _cleanup_strv_free_ gchar **split = NULL;
/* does the description exist? */
gtk_widget_set_visible (priv->box_details_description, tmp != NULL);
if (tmp == NULL)
- goto out;
+ return;
/* add each paragraph as a new GtkLabel which lets us get the 24px
* paragraph spacing */
@@ -498,8 +494,6 @@ gs_shell_details_set_description (GsShellDetails *shell_details, const gchar *tm
gtk_box_pack_start (GTK_BOX (priv->box_details_description), para, FALSE, FALSE, 0);
}
-out:
- g_strfreev (split);
}
/**
@@ -508,13 +502,13 @@ out:
static gboolean
gs_shell_details_is_addon_id_kind (GsApp *app)
{
- AsIdKind id_kind;
- id_kind = gs_app_get_id_kind (app);
- if (id_kind == AS_ID_KIND_DESKTOP)
- return FALSE;
- if (id_kind == AS_ID_KIND_WEB_APP)
- return FALSE;
- return TRUE;
+ AsIdKind id_kind;
+ id_kind = gs_app_get_id_kind (app);
+ if (id_kind == AS_ID_KIND_DESKTOP)
+ return FALSE;
+ if (id_kind == AS_ID_KIND_WEB_APP)
+ return FALSE;
+ return TRUE;
}
/**
@@ -523,15 +517,14 @@ gs_shell_details_is_addon_id_kind (GsApp *app)
static void
gs_shell_details_refresh_all (GsShellDetails *shell_details)
{
- GError *error = NULL;
GPtrArray *history;
GdkPixbuf *pixbuf = NULL;
GList *addons;
GsShellDetailsPrivate *priv = shell_details->priv;
GtkWidget *widget;
const gchar *tmp;
- gchar *size;
guint64 updated;
+ _cleanup_error_free_ GError *error = NULL;
/* change widgets */
tmp = gs_app_get_name (priv->app);
@@ -638,9 +631,9 @@ gs_shell_details_refresh_all (GsShellDetails *shell_details)
/* TRANSLATORS: this is where the size is not known */
gtk_label_set_label (GTK_LABEL (priv->label_details_size_value), C_("size", "Unknown"));
} else {
+ _cleanup_free_ gchar *size = NULL;
size = g_format_size (gs_app_get_size (priv->app));
gtk_label_set_label (GTK_LABEL (priv->label_details_size_value), size);
- g_free (size);
}
/* set the updated date */
@@ -651,11 +644,11 @@ gs_shell_details_refresh_all (GsShellDetails *shell_details)
gtk_label_set_label (GTK_LABEL (priv->label_details_updated_value), C_("updated", "Never"));
} else {
GDateTime *dt;
+ _cleanup_free_ gchar *updated_str = NULL;
dt = g_date_time_new_from_unix_utc (updated);
- size = g_date_time_format (dt, "%x");
+ updated_str = g_date_time_format (dt, "%x");
g_date_time_unref (dt);
- gtk_label_set_label (GTK_LABEL (priv->label_details_updated_value), size);
- g_free (size);
+ gtk_label_set_label (GTK_LABEL (priv->label_details_updated_value), updated_str);
}
/* set the category */
@@ -816,8 +809,8 @@ gs_shell_details_refresh_all (GsShellDetails *shell_details)
static void
list_header_func (GtkListBoxRow *row,
- GtkListBoxRow *before,
- gpointer user_data)
+ GtkListBoxRow *before,
+ gpointer user_data)
{
GtkWidget *header = NULL;
if (before != NULL)
@@ -827,14 +820,14 @@ list_header_func (GtkListBoxRow *row,
static gint
list_sort_func (GtkListBoxRow *a,
- GtkListBoxRow *b,
- gpointer user_data)
+ GtkListBoxRow *b,
+ gpointer user_data)
{
GsApp *a1 = gs_app_addon_row_get_addon (GS_APP_ADDON_ROW (a));
GsApp *a2 = gs_app_addon_row_get_addon (GS_APP_ADDON_ROW (b));
return g_strcmp0 (gs_app_get_name (a1),
- gs_app_get_name (a2));
+ gs_app_get_name (a2));
}
static void gs_shell_details_addon_selected_cb (GsAppAddonRow *row, GParamSpec *pspec, GsShellDetails
*shell_details);
@@ -853,19 +846,19 @@ gs_shell_details_refresh_addons (GsShellDetails *shell_details)
GsApp *addon;
GtkWidget *row;
- addon = g_ptr_array_index (addons, i);
+ addon = g_ptr_array_index (addons, i);
if (gs_app_get_state (addon) == AS_APP_STATE_UNAVAILABLE)
continue;
- row = gs_app_addon_row_new ();
+ row = gs_app_addon_row_new ();
- gs_app_addon_row_set_addon (GS_APP_ADDON_ROW (row), addon);
- gtk_container_add (GTK_CONTAINER (priv->list_box_addons), row);
- gtk_widget_show (row);
+ gs_app_addon_row_set_addon (GS_APP_ADDON_ROW (row), addon);
+ gtk_container_add (GTK_CONTAINER (priv->list_box_addons), row);
+ gtk_widget_show (row);
- g_signal_connect (row, "notify::selected",
- G_CALLBACK (gs_shell_details_addon_selected_cb),
- shell_details);
+ g_signal_connect (row, "notify::selected",
+ G_CALLBACK (gs_shell_details_addon_selected_cb),
+ shell_details);
}
}
@@ -877,12 +870,12 @@ gs_shell_details_app_refine_cb (GObject *source,
GAsyncResult *res,
gpointer user_data)
{
- GError *error = NULL;
GsPluginLoader *plugin_loader = GS_PLUGIN_LOADER (source);
GsShellDetails *shell_details = GS_SHELL_DETAILS (user_data);
GsShellDetailsPrivate *priv = shell_details->priv;
gboolean ret;
- gchar *app_dump;
+ _cleanup_error_free_ GError *error = NULL;
+ _cleanup_free_ gchar *app_dump = NULL;
ret = gs_plugin_loader_app_refine_finish (plugin_loader,
res,
@@ -891,14 +884,12 @@ gs_shell_details_app_refine_cb (GObject *source,
g_warning ("failed to refine %s: %s",
gs_app_get_id (priv->app),
error->message);
- g_error_free (error);
return;
}
/* show some debugging */
app_dump = gs_app_to_string (priv->app);
g_debug ("%s", app_dump);
- g_free (app_dump);
gs_shell_details_refresh_screenshots (shell_details);
gs_shell_details_refresh_addons (shell_details);
@@ -914,11 +905,11 @@ gs_shell_details_filename_to_app_cb (GObject *source,
GAsyncResult *res,
gpointer user_data)
{
- gchar *tmp;
- GError *error = NULL;
GsPluginLoader *plugin_loader = GS_PLUGIN_LOADER (source);
GsShellDetails *shell_details = GS_SHELL_DETAILS (user_data);
GsShellDetailsPrivate *priv = shell_details->priv;
+ _cleanup_error_free_ GError *error = NULL;
+ _cleanup_free_ gchar *tmp = NULL;
if (priv->app != NULL)
g_object_unref (priv->app);
@@ -927,7 +918,6 @@ gs_shell_details_filename_to_app_cb (GObject *source,
&error);
if (priv->app == NULL) {
g_warning ("failed to convert to GsApp: %s", error->message);
- g_error_free (error);
return;
}
@@ -945,7 +935,6 @@ gs_shell_details_filename_to_app_cb (GObject *source,
/* print what we've got */
tmp = gs_app_to_string (priv->app);
g_debug ("%s", tmp);
- g_free (tmp);
/* change widgets */
gs_shell_details_switch_to (shell_details);
@@ -1055,10 +1044,10 @@ gs_shell_details_app_installed_cb (GObject *source,
GAsyncResult *res,
gpointer user_data)
{
- GError *error = NULL;
GsPluginLoader *plugin_loader = GS_PLUGIN_LOADER (source);
GsShellDetailsHelper *helper = (GsShellDetailsHelper *) user_data;
gboolean ret;
+ _cleanup_error_free_ GError *error = NULL;
ret = gs_plugin_loader_app_action_finish (plugin_loader,
res,
@@ -1071,7 +1060,6 @@ gs_shell_details_app_installed_cb (GObject *source,
gs_shell_get_window (helper->shell_details->priv->shell),
GS_PLUGIN_LOADER_ACTION_INSTALL,
error);
- g_error_free (error);
return;
}
@@ -1093,7 +1081,7 @@ gs_shell_details_app_removed_cb (GObject *source,
GAsyncResult *res,
gpointer user_data)
{
- GError *error = NULL;
+ _cleanup_error_free_ GError *error = NULL;
GsPluginLoader *plugin_loader = GS_PLUGIN_LOADER (source);
GsShellDetailsHelper *helper = (GsShellDetailsHelper *) user_data;
gboolean ret;
@@ -1109,7 +1097,6 @@ gs_shell_details_app_removed_cb (GObject *source,
gs_shell_get_window (helper->shell_details->priv->shell),
GS_PLUGIN_LOADER_ACTION_REMOVE,
error);
- g_error_free (error);
return;
}
@@ -1127,9 +1114,9 @@ gs_shell_details_app_remove (GsShellDetails *shell_details, GsApp *app)
{
GsShellDetailsHelper *helper;
GsShellDetailsPrivate *priv = shell_details->priv;
- GString *markup;
GtkResponseType response;
GtkWidget *dialog;
+ _cleanup_string_free_ GString *markup = NULL;
markup = g_string_new ("");
g_string_append_printf (markup,
@@ -1220,7 +1207,8 @@ static void
gs_shell_details_app_install_button_cb (GtkWidget *widget, GsShellDetails *shell_details)
{
GsShellDetailsPrivate *priv = shell_details->priv;
- GList *addons, *l;
+ GList *l;
+ _cleanup_list_free_ GList *addons = NULL;
/* Mark ticked addons to be installed together with the app */
addons = gtk_container_get_children (GTK_CONTAINER (priv->list_box_addons));
@@ -1232,7 +1220,6 @@ gs_shell_details_app_install_button_cb (GtkWidget *widget, GsShellDetails *shell
gs_app_set_to_be_installed (addon, TRUE);
}
}
- g_list_free (addons);
gs_shell_details_app_install (shell_details, priv->app);
}
@@ -1242,8 +1229,8 @@ gs_shell_details_app_install_button_cb (GtkWidget *widget, GsShellDetails *shell
**/
static void
gs_shell_details_addon_selected_cb (GsAppAddonRow *row,
- GParamSpec *pspec,
- GsShellDetails *shell_details)
+ GParamSpec *pspec,
+ GsShellDetails *shell_details)
{
GsShellDetailsPrivate *priv = shell_details->priv;
GsApp *addon;
@@ -1272,11 +1259,11 @@ gs_shell_details_addon_selected_cb (GsAppAddonRow *row,
static void
gs_shell_details_app_launch_button_cb (GtkWidget *widget, GsShellDetails *shell_details)
{
- GAppInfo *appinfo;
- GAppLaunchContext *context;
- GError *error = NULL;
GdkDisplay *display;
const gchar *desktop_id;
+ _cleanup_error_free_ GError *error = NULL;
+ _cleanup_object_unref_ GAppInfo *appinfo = NULL;
+ _cleanup_object_unref_ GAppLaunchContext *context = NULL;
desktop_id = gs_app_get_id (shell_details->priv->app);
display = gdk_display_get_default ();
@@ -1286,13 +1273,8 @@ gs_shell_details_app_launch_button_cb (GtkWidget *widget, GsShellDetails *shell_
return;
}
context = G_APP_LAUNCH_CONTEXT (gdk_display_get_app_launch_context (display));
- if (!g_app_info_launch (appinfo, NULL, context, &error)) {
+ if (!g_app_info_launch (appinfo, NULL, context, &error))
g_warning ("launching %s failed: %s", desktop_id, error->message);
- g_error_free (error);
- }
-
- g_object_unref (appinfo);
- g_object_unref (context);
}
/**
@@ -1317,20 +1299,14 @@ gs_shell_details_app_set_ratings_cb (GObject *source,
GAsyncResult *res,
gpointer user_data)
{
- GError *error = NULL;
GsPluginLoader *plugin_loader = GS_PLUGIN_LOADER (source);
GsShellDetails *shell_details = GS_SHELL_DETAILS (user_data);
GsShellDetailsPrivate *priv = shell_details->priv;
- gboolean ret;
+ _cleanup_error_free_ GError *error = NULL;
- ret = gs_plugin_loader_app_action_finish (plugin_loader,
- res,
- &error);
- if (!ret) {
+ if (!gs_plugin_loader_app_action_finish (plugin_loader, res, &error)) {
g_warning ("failed to set rating %s: %s",
- gs_app_get_id (priv->app),
- error->message);
- g_error_free (error);
+ gs_app_get_id (priv->app), error->message);
}
}
@@ -1411,8 +1387,8 @@ gs_shell_details_setup (GsShellDetails *shell_details,
g_signal_connect (priv->history_dialog, "delete-event",
G_CALLBACK (gtk_widget_hide_on_delete), shell_details);
- adj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (priv->scrolledwindow_details));
- gtk_container_set_focus_vadjustment (GTK_CONTAINER (priv->box_details), adj);
+ adj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (priv->scrolledwindow_details));
+ gtk_container_set_focus_vadjustment (GTK_CONTAINER (priv->box_details), adj);
}
/**
@@ -1490,11 +1466,11 @@ gs_shell_details_init (GsShellDetails *shell_details)
}
gtk_list_box_set_header_func (GTK_LIST_BOX (priv->list_box_addons),
- list_header_func,
- shell_details, NULL);
+ list_header_func,
+ shell_details, NULL);
gtk_list_box_set_sort_func (GTK_LIST_BOX (priv->list_box_addons),
- list_sort_func,
- shell_details, NULL);
+ list_sort_func,
+ shell_details, NULL);
}
/**
diff --git a/src/gs-shell-installed.c b/src/gs-shell-installed.c
index 60a862c..7ce9f0d 100644
--- a/src/gs-shell-installed.c
+++ b/src/gs-shell-installed.c
@@ -26,6 +26,7 @@
#include <glib/gi18n.h>
#include <appstream-glib.h>
+#include "gs-cleanup.h"
#include "gs-shell.h"
#include "gs-shell-installed.h"
#include "gs-app.h"
@@ -75,8 +76,8 @@ gs_shell_installed_invalidate (GsShellInstalled *shell_installed)
static void
gs_shell_installed_app_row_activated_cb (GtkListBox *list_box,
- GtkListBoxRow *row,
- GsShellInstalled *shell_installed)
+ GtkListBoxRow *row,
+ GsShellInstalled *shell_installed)
{
if (shell_installed->priv->selection_mode) {
gboolean selected;
@@ -111,12 +112,12 @@ gs_shell_installed_app_removed_cb (GObject *source,
GAsyncResult *res,
gpointer user_data)
{
- GError *error = NULL;
GsPluginLoader *plugin_loader = GS_PLUGIN_LOADER (source);
GsShellInstalledHelper *helper = (GsShellInstalledHelper *) user_data;
GsShellInstalledPrivate *priv = helper->shell_installed->priv;
GsApp *app;
gboolean ret;
+ _cleanup_error_free_ GError *error = NULL;
ret = gs_plugin_loader_app_action_finish (plugin_loader,
res,
@@ -124,20 +125,18 @@ gs_shell_installed_app_removed_cb (GObject *source,
if (!ret) {
app = gs_app_row_get_app (helper->app_row);
g_warning ("failed to remove %s: %s",
- gs_app_get_id (app),
- error->message);
+ gs_app_get_id (app), error->message);
gs_app_notify_failed_modal (app,
gs_shell_get_window (priv->shell),
GS_PLUGIN_LOADER_ACTION_REMOVE,
error);
- g_error_free (error);
} else {
/* remove from the list */
app = gs_app_row_get_app (helper->app_row);
g_debug ("removed %s", gs_app_get_id (app));
gs_app_row_unreveal (helper->app_row);
g_signal_connect (helper->app_row, "unrevealed",
- G_CALLBACK (row_unrevealed), NULL);
+ G_CALLBACK (row_unrevealed), NULL);
}
g_object_unref (helper->app_row);
@@ -154,10 +153,10 @@ gs_shell_installed_app_remove_cb (GsAppRow *app_row,
{
GsApp *app;
GsShellInstalledPrivate *priv = shell_installed->priv;
- GString *markup;
GtkResponseType response;
GtkWidget *dialog;
GsShellInstalledHelper *helper;
+ _cleanup_string_free_ GString *markup = NULL;
markup = g_string_new ("");
app = gs_app_row_get_app (app_row);
@@ -196,7 +195,6 @@ gs_shell_installed_app_remove_cb (GsAppRow *app_row,
gs_shell_installed_app_removed_cb,
helper);
}
- g_string_free (markup, TRUE);
gtk_widget_destroy (dialog);
}
@@ -242,11 +240,11 @@ gs_shell_installed_add_app (GsShellInstalled *shell, GsApp *app)
gs_app_row_set_app (GS_APP_ROW (app_row), app);
gtk_container_add (GTK_CONTAINER (priv->list_box_install), app_row);
gs_app_row_set_size_groups (GS_APP_ROW (app_row),
- priv->sizegroup_image,
- priv->sizegroup_name);
+ priv->sizegroup_image,
+ priv->sizegroup_name);
gs_app_row_set_selectable (GS_APP_ROW (app_row),
- priv->selection_mode);
+ priv->selection_mode);
gtk_widget_show (app_row);
}
@@ -259,13 +257,13 @@ gs_shell_installed_get_installed_cb (GObject *source_object,
GAsyncResult *res,
gpointer user_data)
{
- GError *error = NULL;
GList *l;
GList *list;
GsApp *app;
GsShellInstalled *shell_installed = GS_SHELL_INSTALLED (user_data);
GsShellInstalledPrivate *priv = shell_installed->priv;
GsPluginLoader *plugin_loader = GS_PLUGIN_LOADER (source_object);
+ _cleanup_error_free_ GError *error = NULL;
gs_stop_spinner (GTK_SPINNER (priv->spinner_install));
gtk_stack_set_visible_child_name (GTK_STACK (priv->stack_install), "view");
@@ -279,7 +277,6 @@ gs_shell_installed_get_installed_cb (GObject *source_object,
if (list == NULL) {
if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
g_warning ("failed to get installed apps: %s", error->message);
- g_error_free (error);
goto out;
}
for (l = list; l != NULL; l = l->next) {
@@ -388,7 +385,7 @@ static gchar *
gs_shell_installed_get_app_sort_key (GsApp *app)
{
GString *key;
- gchar *casefolded_name;
+ _cleanup_free_ gchar *casefolded_name = NULL;
key = g_string_sized_new (64);
@@ -433,7 +430,6 @@ gs_shell_installed_get_app_sort_key (GsApp *app)
/* finally, sort by short name */
casefolded_name = g_utf8_casefold (gs_app_get_name (app), -1);
g_string_append (key, casefolded_name);
- g_free (casefolded_name);
return g_string_free (key, FALSE);
}
@@ -447,14 +443,13 @@ gs_shell_installed_sort_func (GtkListBoxRow *a,
gpointer user_data)
{
GsApp *a1, *a2;
- gchar *key1 = NULL;
- gchar *key2 = NULL;
- gint retval = 0;
+ _cleanup_free_ gchar *key1 = NULL;
+ _cleanup_free_ gchar *key2 = NULL;
/* check valid */
if (!GTK_IS_BIN(a) || !GTK_IS_BIN(b)) {
g_warning ("GtkListBoxRow not valid");
- goto out;
+ return 0;
}
a1 = gs_app_row_get_app (GS_APP_ROW (a));
@@ -463,11 +458,7 @@ gs_shell_installed_sort_func (GtkListBoxRow *a,
key2 = gs_shell_installed_get_app_sort_key (a2);
/* compare the keys according to the algorithm above */
- retval = g_strcmp0 (key1, key2);
-out:
- g_free (key1);
- g_free (key2);
- return retval;
+ return g_strcmp0 (key1, key2);
}
/**
@@ -516,12 +507,12 @@ gs_shell_installed_list_header_func (GtkListBoxRow *row,
* applications and the system ones */
header = gtk_label_new (_("System Applications"));
g_object_set (header,
- "xalign", 0.0,
- NULL);
+ "xalign", 0.0,
+ NULL);
context = gtk_widget_get_style_context (header);
gtk_style_context_add_class (context, "header-label");
} else if (!gs_shell_installed_is_addon_id_kind (gs_app_row_get_app (GS_APP_ROW (before))) &&
- gs_shell_installed_is_addon_id_kind (gs_app_row_get_app (GS_APP_ROW (row)))) {
+ gs_shell_installed_is_addon_id_kind (gs_app_row_get_app (GS_APP_ROW (row)))) {
/* TRANSLATORS: This is the header dividing the normal
* applications and the addons */
header = gtk_label_new (_("Add-ons"));
@@ -538,11 +529,12 @@ gs_shell_installed_list_header_func (GtkListBoxRow *row,
static gboolean
gs_shell_installed_has_app (GsShellInstalled *shell_installed,
- GsApp *app)
+ GsApp *app)
{
GsShellInstalledPrivate *priv = shell_installed->priv;
- GList *children, *l;
+ GList *l;
gboolean ret = FALSE;
+ _cleanup_list_free_ GList *children = NULL;
children = gtk_container_get_children (GTK_CONTAINER (priv->list_box_install));
for (l = children; l; l = l->next) {
@@ -552,8 +544,6 @@ gs_shell_installed_has_app (GsShellInstalled *shell_installed,
break;
}
}
- g_list_free (children);
-
return ret;
}
@@ -564,11 +554,10 @@ static void
gs_shell_installed_pending_apps_changed_cb (GsPluginLoader *plugin_loader,
GsShellInstalled *shell_installed)
{
- GPtrArray *pending;
GsApp *app;
GtkWidget *widget;
- gchar *label;
guint i;
+ _cleanup_ptrarray_unref_ GPtrArray *pending = NULL;
widget = GTK_WIDGET (gtk_builder_get_object (shell_installed->priv->builder,
"button_installed_counter"));
@@ -576,10 +565,10 @@ gs_shell_installed_pending_apps_changed_cb (GsPluginLoader *plugin_loader,
if (pending->len == 0) {
gtk_widget_hide (widget);
} else {
+ _cleanup_free_ gchar *label = NULL;
gtk_widget_show (widget);
label = g_strdup_printf ("%d", pending->len);
gtk_label_set_label (GTK_LABEL (widget), label);
- g_free (label);
}
for (i = 0; i < pending->len; i++) {
app = GS_APP (g_ptr_array_index (pending, i));
@@ -587,18 +576,17 @@ gs_shell_installed_pending_apps_changed_cb (GsPluginLoader *plugin_loader,
if (gs_shell_installed_has_app (shell_installed, app) == FALSE)
gs_shell_installed_add_app (shell_installed, app);
}
-
- g_ptr_array_unref (pending);
}
static void
set_selection_mode (GsShellInstalled *shell_installed, gboolean selection_mode)
{
GsShellInstalledPrivate *priv = shell_installed->priv;
- GList *children, *l;
+ GList *l;
GtkWidget *header;
GtkWidget *widget;
GtkStyleContext *context;
+ _cleanup_list_free_ GList *children = NULL;
if (priv->selection_mode == selection_mode)
return;
@@ -642,9 +630,8 @@ set_selection_mode (GsShellInstalled *shell_installed, gboolean selection_mode)
for (l = children; l; l = l->next) {
GsAppRow *app_row = GS_APP_ROW (l->data);
gs_app_row_set_selectable (app_row,
- priv->selection_mode);
+ priv->selection_mode);
}
- g_list_free (children);
gtk_revealer_set_reveal_child (GTK_REVEALER (priv->bottom_install), priv->selection_mode);
}
@@ -661,7 +648,8 @@ static GList *
get_selected_apps (GsShellInstalled *shell_installed)
{
GsShellInstalledPrivate *priv = shell_installed->priv;
- GList *children, *l, *list;
+ GList *l, *list;
+ _cleanup_list_free_ GList *children = NULL;
list = NULL;
children = gtk_container_get_children (GTK_CONTAINER (priv->list_box_install));
@@ -671,8 +659,6 @@ get_selected_apps (GsShellInstalled *shell_installed)
list = g_list_prepend (list, gs_app_row_get_app (app_row));
}
}
- g_list_free (children);
-
return list;
}
@@ -680,10 +666,11 @@ static void
selection_changed (GsShellInstalled *shell_installed)
{
GsShellInstalledPrivate *priv = shell_installed->priv;
- GsFolders *folders;
- GList *apps, *l;
+ GList *l;
GsApp *app;
gboolean has_folders, has_nonfolders;
+ _cleanup_list_free_ GList *apps = NULL;
+ _cleanup_object_unref_ GsFolders *folders = NULL;
folders = gs_folders_get ();
has_folders = has_nonfolders = FALSE;
@@ -698,8 +685,6 @@ selection_changed (GsShellInstalled *shell_installed)
has_nonfolders = TRUE;
}
}
- g_list_free (apps);
- g_object_unref (folders);
gtk_widget_set_visible (priv->button_folder_add, has_nonfolders);
gtk_widget_set_visible (priv->button_folder_move, has_folders && !has_nonfolders);
@@ -718,12 +703,11 @@ show_folder_dialog (GtkButton *button, GsShellInstalled *shell_installed)
{
GtkWidget *toplevel;
GtkWidget *dialog;
- GList *apps;
+ _cleanup_list_free_ GList *apps = NULL;
toplevel = gtk_widget_get_toplevel (GTK_WIDGET (button));
apps = get_selected_apps (shell_installed);
dialog = gs_app_folder_dialog_new (GTK_WINDOW (toplevel), apps);
- g_list_free (apps);
gtk_window_present (GTK_WINDOW (dialog));
g_signal_connect_swapped (dialog, "delete-event",
G_CALLBACK (folder_dialog_done), shell_installed);
@@ -732,9 +716,10 @@ show_folder_dialog (GtkButton *button, GsShellInstalled *shell_installed)
static void
remove_folders (GtkButton *button, GsShellInstalled *shell_installed)
{
- GList *apps, *l;
- GsFolders *folders;
+ GList *l;
GsApp *app;
+ _cleanup_list_free_ GList *apps = NULL;
+ _cleanup_object_unref_ GsFolders *folders = NULL;
folders = gs_folders_get ();
apps = get_selected_apps (shell_installed);
@@ -745,10 +730,8 @@ remove_folders (GtkButton *button, GsShellInstalled *shell_installed)
gs_app_get_categories (app),
NULL);
}
- g_list_free (apps);
gs_folders_save (folders);
- g_object_unref (folders);
set_selection_mode (shell_installed, FALSE);
}
@@ -757,28 +740,28 @@ static void
select_all_cb (GtkMenuItem *item, GsShellInstalled *shell_installed)
{
GsShellInstalledPrivate *priv = shell_installed->priv;
- GList *children, *l;
+ GList *l;
+ _cleanup_list_free_ GList *children = NULL;
children = gtk_container_get_children (GTK_CONTAINER (priv->list_box_install));
for (l = children; l; l = l->next) {
GsAppRow *app_row = GS_APP_ROW (l->data);
gs_app_row_set_selected (app_row, TRUE);
}
- g_list_free (children);
}
static void
select_none_cb (GtkMenuItem *item, GsShellInstalled *shell_installed)
{
GsShellInstalledPrivate *priv = shell_installed->priv;
- GList *children, *l;
+ GList *l;
+ _cleanup_list_free_ GList *children = NULL;
children = gtk_container_get_children (GTK_CONTAINER (priv->list_box_install));
for (l = children; l; l = l->next) {
GsAppRow *app_row = GS_APP_ROW (l->data);
gs_app_row_set_selected (app_row, FALSE);
}
- g_list_free (children);
}
/**
diff --git a/src/gs-shell-overview.c b/src/gs-shell-overview.c
index 4e8a8c4..8c2203c 100644
--- a/src/gs-shell-overview.c
+++ b/src/gs-shell-overview.c
@@ -23,6 +23,7 @@
#include <glib/gi18n.h>
+#include "gs-cleanup.h"
#include "gs-shell.h"
#include "gs-shell-overview.h"
#include "gs-app.h"
@@ -100,12 +101,12 @@ gs_shell_overview_get_popular_cb (GObject *source_object,
GsShellOverview *shell = GS_SHELL_OVERVIEW (user_data);
GsShellOverviewPrivate *priv = shell->priv;
GsPluginLoader *plugin_loader = GS_PLUGIN_LOADER (source_object);
- GError *error = NULL;
GList *l;
GList *list;
GsApp *app;
gint i;
GtkWidget *tile;
+ _cleanup_error_free_ GError *error = NULL;
/* get popular apps */
list = gs_plugin_loader_get_popular_finish (plugin_loader, res, &error);
@@ -114,7 +115,6 @@ gs_shell_overview_get_popular_cb (GObject *source_object,
if (list == NULL) {
if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
g_warning ("failed to get popular apps: %s", error->message);
- g_error_free (error);
goto out;
}
@@ -142,25 +142,24 @@ out:
static void
gs_shell_overview_get_popular_rotating_cb (GObject *source_object,
- GAsyncResult *res,
- gpointer user_data)
+ GAsyncResult *res,
+ gpointer user_data)
{
GsShellOverview *shell = GS_SHELL_OVERVIEW (user_data);
GsShellOverviewPrivate *priv = shell->priv;
GsPluginLoader *plugin_loader = GS_PLUGIN_LOADER (source_object);
- GError *error = NULL;
GList *l;
GList *list;
GsApp *app;
gint i;
GtkWidget *tile;
+ _cleanup_error_free_ GError *error = NULL;
/* get popular apps */
list = gs_plugin_loader_get_popular_finish (plugin_loader, res, &error);
if (list == NULL) {
if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
g_warning ("failed to get recommended applications: %s", error->message);
- g_error_free (error);
gtk_widget_hide (priv->popular_rotating_heading);
gtk_widget_hide (priv->box_popular_rotating);
goto out;
@@ -216,8 +215,8 @@ gs_shell_overview_get_featured_cb (GObject *source_object,
GsPluginLoader *plugin_loader = GS_PLUGIN_LOADER (source_object);
GtkWidget *tile;
GList *list;
- GError *error = NULL;
GsApp *app;
+ _cleanup_error_free_ GError *error = NULL;
gs_container_remove_all (GTK_CONTAINER (priv->bin_featured));
@@ -226,7 +225,6 @@ gs_shell_overview_get_featured_cb (GObject *source_object,
if (list == NULL) {
if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
g_warning ("failed to get featured apps: %s", error->message);
- g_error_free (error);
goto out;
}
@@ -271,19 +269,18 @@ gs_shell_overview_get_categories_cb (GObject *source_object,
GsShellOverview *shell = GS_SHELL_OVERVIEW (user_data);
GsShellOverviewPrivate *priv = shell->priv;
GsPluginLoader *plugin_loader = GS_PLUGIN_LOADER (source_object);
- GError *error = NULL;
gint i;
GList *l;
GList *list;
GsCategory *cat;
GtkWidget *tile;
gboolean has_category = FALSE;
+ _cleanup_error_free_ GError *error = NULL;
list = gs_plugin_loader_get_categories_finish (plugin_loader, res, &error);
if (list == NULL) {
if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
g_warning ("failed to get categories: %s", error->message);
- g_error_free (error);
goto out;
}
gs_container_remove_all (GTK_CONTAINER (priv->grid_categories));
diff --git a/src/gs-shell-search-provider.c b/src/gs-shell-search-provider.c
index b2ae7aa..109c690 100644
--- a/src/gs-shell-search-provider.c
+++ b/src/gs-shell-search-provider.c
@@ -29,6 +29,7 @@
#include "gs-plugin-loader-sync.h"
+#include "gs-cleanup.h"
#include "gs-shell-search-provider-generated.h"
#include "gs-shell-search-provider.h"
@@ -110,10 +111,10 @@ search_done_cb (GObject *source,
static void
execute_search (GsShellSearchProvider *self,
GDBusMethodInvocation *invocation,
- gchar **terms)
+ gchar **terms)
{
PendingSearch *pending_search;
- gchar *string;
+ _cleanup_free_ gchar *string = NULL;
string = g_strjoinv (" ", terms);
@@ -138,14 +139,13 @@ execute_search (GsShellSearchProvider *self,
string, 0, self->cancellable,
search_done_cb,
pending_search);
- g_free (string);
}
static gboolean
-handle_get_initial_result_set (GsShellSearchProvider2 *skeleton,
- GDBusMethodInvocation *invocation,
- gchar **terms,
- gpointer user_data)
+handle_get_initial_result_set (GsShellSearchProvider2 *skeleton,
+ GDBusMethodInvocation *invocation,
+ gchar **terms,
+ gpointer user_data)
{
GsShellSearchProvider *self = user_data;
@@ -155,11 +155,11 @@ handle_get_initial_result_set (GsShellSearchProvider2 *skeleton,
}
static gboolean
-handle_get_subsearch_result_set (GsShellSearchProvider2 *skeleton,
- GDBusMethodInvocation *invocation,
- gchar **previous_results,
- gchar **terms,
- gpointer user_data)
+handle_get_subsearch_result_set (GsShellSearchProvider2 *skeleton,
+ GDBusMethodInvocation *invocation,
+ gchar **previous_results,
+ gchar **terms,
+ gpointer user_data)
{
GsShellSearchProvider *self = user_data;
@@ -169,10 +169,10 @@ handle_get_subsearch_result_set (GsShellSearchProvider2 *skeleton,
}
static gboolean
-handle_get_result_metas (GsShellSearchProvider2 *skeleton,
- GDBusMethodInvocation *invocation,
- gchar **results,
- gpointer user_data)
+handle_get_result_metas (GsShellSearchProvider2 *skeleton,
+ GDBusMethodInvocation *invocation,
+ gchar **results,
+ gpointer user_data)
{
GsShellSearchProvider *self = user_data;
GVariantBuilder meta;
@@ -185,7 +185,7 @@ handle_get_result_metas (GsShellSearchProvider2 *skeleton,
g_debug ("****** GetResultMetas");
for (i = 0; results[i]; i++) {
- GsApp *app;
+ _cleanup_object_unref_ GsApp *app = NULL;
if (g_hash_table_lookup (self->metas_cache, results[i]))
continue;
@@ -213,7 +213,6 @@ handle_get_result_metas (GsShellSearchProvider2 *skeleton,
g_variant_builder_add (&meta, "{sv}", "description", g_variant_new_string (gs_app_get_summary
(app)));
meta_variant = g_variant_builder_end (&meta);
g_hash_table_insert (self->metas_cache, g_strdup (gs_app_get_id (app)), g_variant_ref_sink
(meta_variant));
- g_object_unref (app);
}
@@ -232,39 +231,36 @@ handle_get_result_metas (GsShellSearchProvider2 *skeleton,
static gboolean
handle_activate_result (GsShellSearchProvider2 *skeleton,
- GDBusMethodInvocation *invocation,
- gchar *result,
- gchar **terms,
- guint32 timestamp,
- gpointer user_data)
+ GDBusMethodInvocation *invocation,
+ gchar *result,
+ gchar **terms,
+ guint32 timestamp,
+ gpointer user_data)
{
GApplication *app = g_application_get_default ();
- gchar *string;
+ _cleanup_free_ gchar *string = NULL;
string = g_strjoinv (" ", terms);
g_action_group_activate_action (G_ACTION_GROUP (app), "details",
- g_variant_new ("(ss)", result, string));
+ g_variant_new ("(ss)", result, string));
- g_free (string);
gs_shell_search_provider2_complete_activate_result (skeleton, invocation);
return TRUE;
}
static gboolean
handle_launch_search (GsShellSearchProvider2 *skeleton,
- GDBusMethodInvocation *invocation,
- gchar **terms,
- guint32 timestamp,
- gpointer user_data)
+ GDBusMethodInvocation *invocation,
+ gchar **terms,
+ guint32 timestamp,
+ gpointer user_data)
{
GApplication *app = g_application_get_default ();
- gchar *string = g_strjoinv (" ", terms);
+ _cleanup_free_ gchar *string = g_strjoinv (" ", terms);
g_action_group_activate_action (G_ACTION_GROUP (app), "search",
- g_variant_new ("s", string));
-
- g_free (string);
+ g_variant_new ("s", string));
gs_shell_search_provider2_complete_launch_search (skeleton, invocation);
return TRUE;
@@ -272,24 +268,24 @@ handle_launch_search (GsShellSearchProvider2 *skeleton,
static void
search_provider_name_acquired_cb (GDBusConnection *connection,
- const gchar *name,
- gpointer user_data)
+ const gchar *name,
+ gpointer user_data)
{
g_debug ("Search provider name acquired: %s", name);
}
static void
search_provider_name_lost_cb (GDBusConnection *connection,
- const gchar *name,
- gpointer user_data)
+ const gchar *name,
+ gpointer user_data)
{
g_debug ("Search provider name lost: %s", name);
}
static void
search_provider_bus_acquired_cb (GDBusConnection *connection,
- const gchar *name,
- gpointer user_data)
+ const gchar *name,
+ gpointer user_data)
{
GsShellSearchProvider *self = user_data;
diff --git a/src/gs-shell-search.c b/src/gs-shell-search.c
index f9ffb41..7e461ab 100644
--- a/src/gs-shell-search.c
+++ b/src/gs-shell-search.c
@@ -24,6 +24,7 @@
#include <string.h>
#include <glib/gi18n.h>
+#include "gs-cleanup.h"
#include "gs-shell-search.h"
#include "gs-shell.h"
#include "gs-app.h"
@@ -54,11 +55,10 @@ G_DEFINE_TYPE_WITH_PRIVATE (GsShellSearch, gs_shell_search, GTK_TYPE_BIN)
static void
gs_shell_search_app_row_activated_cb (GtkListBox *list_box,
- GtkListBoxRow *row,
- GsShellSearch *shell_search)
+ GtkListBoxRow *row,
+ GsShellSearch *shell_search)
{
GsApp *app;
-
app = gs_app_row_get_app (GS_APP_ROW (row));
gs_shell_show_app (shell_search->priv->shell, app);
}
@@ -73,10 +73,10 @@ gs_shell_search_app_installed_cb (GObject *source,
GAsyncResult *res,
gpointer user_data)
{
- GError *error = NULL;
GsPluginLoader *plugin_loader = GS_PLUGIN_LOADER (source);
GsShellSearchHelper *helper = (GsShellSearchHelper *) user_data;
gboolean ret;
+ _cleanup_error_free_ GError *error = NULL;
ret = gs_plugin_loader_app_action_finish (plugin_loader,
res,
@@ -89,7 +89,6 @@ gs_shell_search_app_installed_cb (GObject *source,
gs_shell_get_window (helper->shell_search->priv->shell),
GS_PLUGIN_LOADER_ACTION_INSTALL,
error);
- g_error_free (error);
} else {
/* only show this if the window is not active */
if (!gs_shell_is_active (helper->shell_search->priv->shell))
@@ -109,22 +108,20 @@ gs_shell_search_app_removed_cb (GObject *source,
GAsyncResult *res,
gpointer user_data)
{
- GError *error = NULL;
GsPluginLoader *plugin_loader = GS_PLUGIN_LOADER (source);
GsShellSearchHelper *helper = (GsShellSearchHelper *) user_data;
gboolean ret;
+ _cleanup_error_free_ GError *error = NULL;
ret = gs_plugin_loader_app_action_finish (plugin_loader,
res,
&error);
if (!ret) {
- g_warning ("failed to remove: %s",
- error->message);
+ g_warning ("failed to remove: %s", error->message);
gs_app_notify_failed_modal (helper->app,
gs_shell_get_window (helper->shell_search->priv->shell),
GS_PLUGIN_LOADER_ACTION_REMOVE,
error);
- g_error_free (error);
}
gs_shell_search_reload (helper->shell_search);
g_object_unref (helper->app);
@@ -139,9 +136,9 @@ static void
gs_shell_search_app_remove (GsShellSearch *shell_search, GsApp *app)
{
GsShellSearchPrivate *priv = shell_search->priv;
- GString *markup;
GtkResponseType response;
GtkWidget *dialog;
+ _cleanup_string_free_ GString *markup = NULL;
markup = g_string_new ("");
g_string_append_printf (markup,
@@ -177,7 +174,6 @@ gs_shell_search_app_remove (GsShellSearch *shell_search, GsApp *app)
gs_shell_search_app_removed_cb,
helper);
}
- g_string_free (markup, TRUE);
gtk_widget_destroy (dialog);
}
@@ -206,16 +202,12 @@ gs_shell_search_app_install (GsShellSearch *shell_search, GsApp *app)
static void
gs_shell_search_show_missing_url (GsApp *app)
{
- GError *error = NULL;
const gchar *url;
- gboolean ret;
+ _cleanup_error_free_ GError *error = NULL;
url = gs_app_get_url (app, AS_URL_KIND_MISSING);
- ret = gtk_show_uri (NULL, url, GDK_CURRENT_TIME, &error);
- if (!ret) {
+ if (!gtk_show_uri (NULL, url, GDK_CURRENT_TIME, &error))
g_warning ("spawn of '%s' failed", url);
- g_error_free (error);
- }
}
/**
@@ -249,7 +241,7 @@ gs_shell_search_install_unavailable_app (GsShellSearch *shell_search, GsApp *app
**/
static void
gs_shell_search_app_row_clicked_cb (GsAppRow *app_row,
- GsShellSearch *shell_search)
+ GsShellSearch *shell_search)
{
GsApp *app;
app = gs_app_row_get_app (app_row);
@@ -274,7 +266,6 @@ gs_shell_search_get_search_cb (GObject *source_object,
GAsyncResult *res,
gpointer user_data)
{
- GError *error = NULL;
GList *l;
GList *list;
GsApp *app;
@@ -282,29 +273,24 @@ gs_shell_search_get_search_cb (GObject *source_object,
GsShellSearchPrivate *priv = shell_search->priv;
GsPluginLoader *plugin_loader = GS_PLUGIN_LOADER (source_object);
GtkWidget *app_row;
+ _cleanup_error_free_ GError *error = NULL;
list = gs_plugin_loader_search_finish (plugin_loader, res, &error);
if (list == NULL) {
- if (g_error_matches (error,
- G_IO_ERROR,
- G_IO_ERROR_CANCELLED)) {
+ if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
g_debug ("search cancelled");
- g_error_free (error);
- goto out;
+ return;
}
-
if (g_error_matches (error,
GS_PLUGIN_LOADER_ERROR,
GS_PLUGIN_LOADER_ERROR_NO_RESULTS)) {
g_debug ("no search results to show");
} else {
- g_warning ("failed to get search apps: %s",
- error->message);
+ g_warning ("failed to get search apps: %s", error->message);
}
- g_error_free (error);
gs_stop_spinner (GTK_SPINNER (priv->spinner_search));
gtk_stack_set_visible_child_name (GTK_STACK (priv->stack_search), "no-results");
- goto out;
+ return;
}
gs_stop_spinner (GTK_SPINNER (priv->spinner_search));
@@ -318,8 +304,8 @@ gs_shell_search_get_search_cb (GObject *source_object,
gs_app_row_set_app (GS_APP_ROW (app_row), app);
gtk_container_add (GTK_CONTAINER (priv->list_box_search), app_row);
gs_app_row_set_size_groups (GS_APP_ROW (app_row),
- priv->sizegroup_image,
- priv->sizegroup_name);
+ priv->sizegroup_image,
+ priv->sizegroup_name);
gtk_widget_show (app_row);
}
@@ -327,8 +313,6 @@ gs_shell_search_get_search_cb (GObject *source_object,
gs_shell_show_details (priv->shell, priv->appid_to_show);
g_clear_pointer (&priv->appid_to_show, g_free);
}
-
-out: ;
}
/**
@@ -413,11 +397,11 @@ gs_shell_search_switch_to (GsShellSearch *shell_search, const gchar *value, gboo
widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "search_bar"));
gtk_widget_show (widget);
- if (scroll_up) {
- GtkAdjustment *adj;
- adj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW
(priv->scrolledwindow_search));
- gtk_adjustment_set_value (adj, gtk_adjustment_get_lower (adj));
- }
+ if (scroll_up) {
+ GtkAdjustment *adj;
+ adj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (priv->scrolledwindow_search));
+ gtk_adjustment_set_value (adj, gtk_adjustment_get_lower (adj));
+ }
g_free (priv->value);
priv->value = g_strdup (value);
@@ -496,17 +480,11 @@ gs_shell_search_sort_func (GtkListBoxRow *a,
{
GsApp *a1 = gs_app_row_get_app (GS_APP_ROW (a));
GsApp *a2 = gs_app_row_get_app (GS_APP_ROW (b));
- gchar *key1 = gs_shell_search_get_app_sort_key (a1);
- gchar *key2 = gs_shell_search_get_app_sort_key (a2);
- gint retval;
+ _cleanup_free_ gchar *key1 = gs_shell_search_get_app_sort_key (a1);
+ _cleanup_free_ gchar *key2 = gs_shell_search_get_app_sort_key (a2);
/* compare the keys according to the algorithm above */
- retval = g_strcmp0 (key2, key1);
-
- g_free (key1);
- g_free (key2);
-
- return retval;
+ return g_strcmp0 (key2, key1);
}
/**
diff --git a/src/gs-shell-updates.c b/src/gs-shell-updates.c
index a5baf2a..f9f3f11 100644
--- a/src/gs-shell-updates.c
+++ b/src/gs-shell-updates.c
@@ -24,6 +24,7 @@
#include <glib/gi18n.h>
#include <packagekit-glib2/packagekit.h>
+#include "gs-cleanup.h"
#include "gs-shell.h"
#include "gs-shell-updates.h"
#include "gs-utils.h"
@@ -105,9 +106,9 @@ time_next_midnight (void)
now = g_date_time_new_now_local ();
since_midnight = g_date_time_get_hour (now) * G_TIME_SPAN_HOUR +
- g_date_time_get_minute (now) * G_TIME_SPAN_MINUTE +
- g_date_time_get_second (now) * G_TIME_SPAN_SECOND +
- g_date_time_get_microsecond (now);
+ g_date_time_get_minute (now) * G_TIME_SPAN_MINUTE +
+ g_date_time_get_second (now) * G_TIME_SPAN_SECOND +
+ g_date_time_get_microsecond (now);
next_midnight = g_date_time_add (now, G_TIME_SPAN_DAY - since_midnight);
g_date_time_unref (now);
@@ -205,11 +206,12 @@ gs_shell_updates_get_state_string (GsPluginStatus status)
static void
gs_shell_updates_update_ui_state (GsShellUpdates *shell_updates)
{
- gchar *tmp;
GsShellUpdatesPrivate *priv = shell_updates->priv;
GtkWidget *widget;
PkNetworkEnum network_state;
gboolean is_free_connection;
+ _cleanup_free_ gchar *checked_str = NULL;
+ _cleanup_free_ gchar *spinner_str = NULL;
if (gs_shell_get_mode (shell_updates->priv->shell) != GS_SHELL_MODE_UPDATES)
return;
@@ -248,19 +250,17 @@ gs_shell_updates_update_ui_state (GsShellUpdates *shell_updates)
/* spinner text */
switch (priv->state) {
case GS_SHELL_UPDATES_STATE_STARTUP:
- tmp = g_strdup_printf ("%s\n%s",
+ spinner_str = g_strdup_printf ("%s\n%s",
/* TRANSLATORS: the updates panel is starting up */
_("Setting up updates…"),
_("(This could take a while)"));
- gtk_label_set_label (GTK_LABEL (priv->label_updates_spinner), tmp);
- g_free (tmp);
+ gtk_label_set_label (GTK_LABEL (priv->label_updates_spinner), spinner_str);
case GS_SHELL_UPDATES_STATE_ACTION_REFRESH_NO_UPDATES:
- tmp = g_strdup_printf ("%s\n%s",
+ spinner_str = g_strdup_printf ("%s\n%s",
gs_shell_updates_get_state_string (priv->last_status),
/* TRANSLATORS: the updates panel is starting up */
_("(This could take a while)"));
- gtk_label_set_label (GTK_LABEL (priv->label_updates_spinner), tmp);
- g_free (tmp);
+ gtk_label_set_label (GTK_LABEL (priv->label_updates_spinner), spinner_str);
break;
case GS_SHELL_UPDATES_STATE_ACTION_GET_UPDATES:
/* TRANSLATORS: this is when the updates panel is starting up */
@@ -393,18 +393,16 @@ gs_shell_updates_update_ui_state (GsShellUpdates *shell_updates)
/* last checked label */
if (g_strcmp0 (gtk_stack_get_visible_child_name (GTK_STACK (priv->stack_updates)), "uptodate") == 0) {
- tmp = gs_shell_updates_last_checked_time_string (shell_updates);
- if (tmp != NULL) {
- gchar *last_checked;
+ checked_str = gs_shell_updates_last_checked_time_string (shell_updates);
+ if (checked_str != NULL) {
+ _cleanup_free_ gchar *last_checked = NULL;
/* TRANSLATORS: This is the time when we last checked for updates */
- last_checked = g_strdup_printf (_("Last checked: %s"), tmp);
+ last_checked = g_strdup_printf (_("Last checked: %s"), checked_str);
gtk_label_set_label (GTK_LABEL (priv->label_updates_last_checked),
- last_checked);
- g_free (last_checked);
+ last_checked);
}
- gtk_widget_set_visible (priv->label_updates_last_checked, tmp != NULL);
- g_free (tmp);
+ gtk_widget_set_visible (priv->label_updates_last_checked, checked_str != NULL);
}
}
@@ -438,11 +436,11 @@ gs_shell_updates_get_updates_cb (GsPluginLoader *plugin_loader,
GAsyncResult *res,
GsShellUpdates *shell_updates)
{
- GError *error = NULL;
GList *l;
GList *list;
GsShellUpdatesPrivate *priv = shell_updates->priv;
GtkWidget *widget;
+ _cleanup_error_free_ GError *error = NULL;
priv->cache_valid = TRUE;
@@ -450,22 +448,21 @@ gs_shell_updates_get_updates_cb (GsPluginLoader *plugin_loader,
list = gs_plugin_loader_get_updates_finish (plugin_loader, res, &error);
for (l = list; l != NULL; l = l->next) {
gs_update_list_add_app (GS_UPDATE_LIST (priv->list_box_updates),
- GS_APP (l->data));
+ GS_APP (l->data));
}
widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "button_updates_counter"));
if (list != NULL) {
- gchar *text;
+ _cleanup_free_ gchar *text = NULL;
text = g_strdup_printf ("%d", g_list_length (list));
gtk_label_set_label (GTK_LABEL (widget), text);
- g_free (text);
gtk_widget_show (widget);
} else {
gtk_widget_hide (widget);
}
if (list != NULL &&
- gs_shell_get_mode (priv->shell) != GS_SHELL_MODE_UPDATES)
+ gs_shell_get_mode (priv->shell) != GS_SHELL_MODE_UPDATES)
gtk_style_context_add_class (gtk_widget_get_style_context (widget), "needs-attention");
else
gtk_style_context_remove_class (gtk_widget_get_style_context (widget), "needs-attention");
@@ -481,11 +478,10 @@ gs_shell_updates_get_updates_cb (GsPluginLoader *plugin_loader,
if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
g_warning ("failed to get updates: %s", error->message);
gtk_label_set_label (GTK_LABEL (priv->label_updates_failed),
- error->message);
+ error->message);
gs_shell_updates_set_state (shell_updates,
GS_SHELL_UPDATES_STATE_FAILED);
}
- g_error_free (error);
} else {
gs_shell_updates_set_state (shell_updates,
GS_SHELL_UPDATES_STATE_HAS_UPDATES);
@@ -607,10 +603,10 @@ gs_shell_updates_refresh_cb (GsPluginLoader *plugin_loader,
GAsyncResult *res,
GsShellUpdates *shell_updates)
{
- GError *error = NULL;
gboolean ret;
GDateTime *now;
GsShellUpdatesPrivate *priv = shell_updates->priv;
+ _cleanup_error_free_ GError *error = NULL;
/* get the results */
ret = gs_plugin_loader_refresh_finish (plugin_loader, res, &error);
@@ -636,17 +632,16 @@ gs_shell_updates_refresh_cb (GsPluginLoader *plugin_loader,
}
g_warning ("failed to refresh: %s", error->message);
gtk_label_set_label (GTK_LABEL (priv->label_updates_failed),
- error->message);
+ error->message);
gs_shell_updates_set_state (shell_updates,
GS_SHELL_UPDATES_STATE_FAILED);
- g_error_free (error);
return;
}
/* update the last checked timestamp */
now = g_date_time_new_now_local ();
g_settings_set (priv->settings, "check-timestamp", "x",
- g_date_time_to_unix (now));
+ g_date_time_to_unix (now));
g_date_time_unref (now);
/* get the new list */
@@ -688,14 +683,9 @@ gs_shell_updates_get_new_updates (GsShellUpdates *shell_updates)
static void
gs_shell_updates_show_network_settings (GsShellUpdates *shell_updates)
{
- gboolean ret;
- GError *error = NULL;
-
- ret = g_spawn_command_line_async ("gnome-control-center network", &error);
- if (!ret) {
+ _cleanup_error_free_ GError *error = NULL;
+ if (!g_spawn_command_line_async ("gnome-control-center network", &error))
g_warning ("Failed to open the control center: %s", error->message);
- g_error_free (error);
- }
}
/**
@@ -791,7 +781,7 @@ gs_shell_updates_button_refresh_cb (GtkWidget *widget,
_("Internet access is required to check for
updates."));
gtk_dialog_add_button (GTK_DIALOG (dialog),
/* TRANSLATORS: this is a link to the
- * control-center network panel */
+ * control-center network panel */
_("Network Settings"),
GTK_RESPONSE_REJECT);
g_signal_connect (dialog, "response",
@@ -818,7 +808,7 @@ gs_shell_updates_button_refresh_cb (GtkWidget *widget,
_("Checking for updates while using mobile
broadband could cause you to incur charges."));
gtk_dialog_add_button (GTK_DIALOG (dialog),
/* TRANSLATORS: this is a link to the
- * control-center network panel */
+ * control-center network panel */
_("Check Anyway"),
GTK_RESPONSE_ACCEPT);
g_signal_connect (dialog, "response",
@@ -844,22 +834,18 @@ gs_shell_updates_pending_apps_changed_cb (GsPluginLoader *plugin_loader,
static void
gs_offline_updates_cancel (void)
{
- GError *error = NULL;
- if (!pk_offline_cancel (NULL, &error)) {
+ _cleanup_error_free_ GError *error = NULL;
+ if (!pk_offline_cancel (NULL, &error))
g_warning ("failed to cancel the offline update: %s", error->message);
- g_error_free (error);
- return;
- }
}
static void
gs_shell_updates_button_update_all_cb (GtkButton *button,
GsShellUpdates *updates)
{
- GError *error = NULL;
+ _cleanup_error_free_ GError *error = NULL;
if (!pk_offline_trigger (PK_OFFLINE_ACTION_REBOOT, NULL, &error)) {
g_warning ("failed to trigger an offline update: %s", error->message);
- g_error_free (error);
return;
}
gs_reboot (gs_offline_updates_cancel);
@@ -873,17 +859,13 @@ gs_shell_updates_get_properties_cb (GObject *source,
GAsyncResult *res,
gpointer user_data)
{
- gboolean ret;
- GError *error = NULL;
GsShellUpdates *shell_updates = GS_SHELL_UPDATES (user_data);
PkControl *control = PK_CONTROL (source);
+ _cleanup_error_free_ GError *error = NULL;
/* get result */
- ret = pk_control_get_properties_finish (control, res, &error);
- if (!ret) {
+ if (!pk_control_get_properties_finish (control, res, &error))
g_warning ("failed to get properties: %s", error->message);
- g_error_free (error);
- }
gs_shell_updates_update_ui_state (shell_updates);
}
diff --git a/src/gs-shell.c b/src/gs-shell.c
index 29279f2..e9e7428 100644
--- a/src/gs-shell.c
+++ b/src/gs-shell.c
@@ -25,6 +25,7 @@
#include <string.h>
#include <glib/gi18n.h>
+#include "gs-cleanup.h"
#include "gs-utils.h"
#include "gs-shell.h"
#include "gs-shell-details.h"
@@ -271,9 +272,8 @@ gs_shell_back_button_cb (GtkWidget *widget, GsShell *shell)
gs_shell_change_mode (shell, entry->mode, entry->app, entry->category, FALSE);
- if (entry->focus) {
+ if (entry->focus != NULL)
gtk_widget_grab_focus (entry->focus);
- }
free_back_entry (entry);
}
@@ -370,7 +370,8 @@ window_keypress_handler (GtkWidget *window, GdkEvent *event, GsShell *shell)
gboolean preedit_changed;
guint preedit_change_id;
gboolean res;
- gchar *old_text, *new_text;
+ _cleanup_free_ gchar *old_text = NULL;
+ _cleanup_free_ gchar *new_text = NULL;
if (gs_shell_get_mode (shell) != GS_SHELL_MODE_OVERVIEW &&
gs_shell_get_mode (shell) != GS_SHELL_MODE_SEARCH)
@@ -399,9 +400,6 @@ window_keypress_handler (GtkWidget *window, GdkEvent *event, GsShell *shell)
preedit_changed)
handled = GDK_EVENT_STOP;
- g_free (old_text);
- g_free (new_text);
-
/* We set "editable" so the text in the entry won't get selected on focus */
g_object_set (entry, "editable", FALSE, NULL);
gtk_widget_grab_focus (entry);
@@ -533,7 +531,7 @@ gs_shell_setup (GsShell *shell, GsPluginLoader *plugin_loader, GCancellable *can
GS_DATA G_DIR_SEPARATOR_S "icons");
g_signal_connect (priv->main_window, "delete-event",
- G_CALLBACK (main_window_closed_cb), shell);
+ G_CALLBACK (main_window_closed_cb), shell);
/* fix up the header bar */
widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "header"));
@@ -660,13 +658,13 @@ gs_shell_get_mode_string (GsShell *shell)
static void
gs_shell_get_installed_updates_cb (GsPluginLoader *plugin_loader,
- GAsyncResult *res,
- GsShell *shell)
+ GAsyncResult *res,
+ GsShell *shell)
{
GsShellPrivate *priv = shell->priv;
- GError *error = NULL;
GList *list;
GtkWidget *dialog;
+ _cleanup_error_free_ GError *error = NULL;
/* get the results */
list = gs_plugin_loader_get_updates_finish (plugin_loader, res, &error);
@@ -676,13 +674,12 @@ gs_shell_get_installed_updates_cb (GsPluginLoader *plugin_loader,
GS_PLUGIN_LOADER_ERROR_NO_RESULTS)) {
g_debug ("no updates to show");
} else if (g_error_matches (error,
- G_IO_ERROR,
- G_IO_ERROR_CANCELLED)) {
+ G_IO_ERROR,
+ G_IO_ERROR_CANCELLED)) {
g_debug ("get updates cancelled");
} else {
g_warning ("failed to get updates: %s", error->message);
}
- g_error_free (error);
goto out;
}
@@ -704,15 +701,15 @@ gs_shell_show_installed_updates (GsShell *shell)
guint64 refine_flags;
refine_flags = GS_PLUGIN_REFINE_FLAGS_DEFAULT |
- GS_PLUGIN_REFINE_FLAGS_REQUIRE_UPDATE_DETAILS |
- GS_PLUGIN_REFINE_FLAGS_REQUIRE_VERSION |
- GS_PLUGIN_REFINE_FLAGS_USE_HISTORY;
+ GS_PLUGIN_REFINE_FLAGS_REQUIRE_UPDATE_DETAILS |
+ GS_PLUGIN_REFINE_FLAGS_REQUIRE_VERSION |
+ GS_PLUGIN_REFINE_FLAGS_USE_HISTORY;
gs_plugin_loader_get_updates_async (priv->plugin_loader,
- refine_flags,
- priv->cancellable,
- (GAsyncReadyCallback) gs_shell_get_installed_updates_cb,
- shell);
+ refine_flags,
+ priv->cancellable,
+ (GAsyncReadyCallback) gs_shell_get_installed_updates_cb,
+ shell);
}
void
@@ -771,7 +768,7 @@ gs_shell_show_search_result (GsShell *shell, const gchar *id, const gchar *searc
widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "entry_search"));
/* ignore next "search-changed" signal to avoid getting a callback
- * after 150 ms and messing up the state */
+ * after 150 ms and messing up the state */
priv->ignore_next_search_changed_signal = TRUE;
gtk_entry_set_text (GTK_ENTRY (widget), search);
@@ -782,11 +779,9 @@ gs_shell_show_search_result (GsShell *shell, const gchar *id, const gchar *searc
void
gs_shell_show_details (GsShell *shell, const gchar *id)
{
- GsApp *app;
-
+ _cleanup_object_unref_ GsApp *app = NULL;
app = gs_app_new (id);
gs_shell_show_app (shell, app);
- g_object_unref (app);
}
/**
diff --git a/src/gs-sources-dialog.c b/src/gs-sources-dialog.c
index e26e369..21c8412 100644
--- a/src/gs-sources-dialog.c
+++ b/src/gs-sources-dialog.c
@@ -25,6 +25,7 @@
#include <glib/gi18n.h>
#include <gtk/gtk.h>
+#include "gs-cleanup.h"
#include "gs-sources-dialog.h"
#include "gs-utils.h"
@@ -53,10 +54,10 @@ add_source (GtkListBox *listbox, GsApp *app)
GtkWidget *box;
GtkStyleContext *context;
GPtrArray *related;
- gchar *text;
guint cnt_addon = 0;
guint cnt_apps = 0;
guint i;
+ _cleanup_free_ gchar *text = NULL;
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
gtk_widget_set_margin_top (box, 12);
@@ -107,7 +108,6 @@ add_source (GtkListBox *listbox, GsApp *app)
cnt_apps, cnt_addon);
}
widget = gtk_label_new (text);
- g_free (text);
gtk_widget_set_halign (widget, GTK_ALIGN_START);
gtk_box_pack_start (GTK_BOX (box), widget, FALSE, FALSE, 0);
@@ -123,14 +123,14 @@ add_source (GtkListBox *listbox, GsApp *app)
static void
get_sources_cb (GsPluginLoader *plugin_loader,
- GAsyncResult *res,
- GsSourcesDialog *dialog)
+ GAsyncResult *res,
+ GsSourcesDialog *dialog)
{
- GError *error = NULL;
GList *l;
GList *list;
GsApp *app;
GsSourcesDialogPrivate *priv = gs_sources_dialog_get_instance_private (dialog);
+ _cleanup_error_free_ GError *error = NULL;
/* show results */
gs_stop_spinner (GTK_SPINNER (priv->spinner));
@@ -143,13 +143,12 @@ get_sources_cb (GsPluginLoader *plugin_loader,
GS_PLUGIN_LOADER_ERROR_NO_RESULTS)) {
g_debug ("no sources to show");
} else if (g_error_matches (error,
- G_IO_ERROR,
- G_IO_ERROR_CANCELLED)) {
+ G_IO_ERROR,
+ G_IO_ERROR_CANCELLED)) {
g_debug ("get sources cancelled");
} else {
g_warning ("failed to get sources: %s", error->message);
}
- g_error_free (error);
gtk_stack_set_visible_child_name (GTK_STACK (priv->stack), "empty");
goto out;
}
@@ -186,8 +185,8 @@ reload_sources (GsSourcesDialog *dialog)
static void
list_header_func (GtkListBoxRow *row,
- GtkListBoxRow *before,
- gpointer user_data)
+ GtkListBoxRow *before,
+ gpointer user_data)
{
GtkWidget *header = NULL;
if (before != NULL)
@@ -197,8 +196,8 @@ list_header_func (GtkListBoxRow *row,
static gint
list_sort_func (GtkListBoxRow *a,
- GtkListBoxRow *b,
- gpointer user_data)
+ GtkListBoxRow *b,
+ gpointer user_data)
{
return a < b;
}
@@ -226,8 +225,8 @@ add_app (GtkListBox *listbox, GsApp *app)
static void
list_row_activated_cb (GtkListBox *list_box,
- GtkListBoxRow *row,
- GsSourcesDialog *dialog)
+ GtkListBoxRow *row,
+ GsSourcesDialog *dialog)
{
GPtrArray *related;
GsApp *app;
@@ -276,21 +275,16 @@ back_button_cb (GtkWidget *widget, GsSourcesDialog *dialog)
static void
app_removed_cb (GObject *source,
- GAsyncResult *res,
- gpointer user_data)
+ GAsyncResult *res,
+ gpointer user_data)
{
- GError *error = NULL;
GsPluginLoader *plugin_loader = GS_PLUGIN_LOADER (source);
GsSourcesDialog *dialog = GS_SOURCES_DIALOG (user_data);
GsSourcesDialogPrivate *priv = gs_sources_dialog_get_instance_private (dialog);
- gboolean ret;
+ _cleanup_error_free_ GError *error = NULL;
- ret = gs_plugin_loader_app_action_finish (plugin_loader,
- res,
- &error);
- if (!ret) {
+ if (!gs_plugin_loader_app_action_finish (plugin_loader, res, &error)) {
g_warning ("failed to remove: %s", error->message);
- g_error_free (error);
} else {
reload_sources (dialog);
}
@@ -412,10 +406,10 @@ gs_sources_dialog_new (GtkWindow *parent, GsPluginLoader *plugin_loader)
GsSourcesDialog *dialog;
dialog = g_object_new (GS_TYPE_SOURCES_DIALOG,
- "use-header-bar", TRUE,
+ "use-header-bar", TRUE,
"transient-for", parent,
"modal", TRUE,
- NULL);
+ NULL);
set_plugin_loader (dialog, plugin_loader);
reload_sources (dialog);
diff --git a/src/gs-update-dialog.c b/src/gs-update-dialog.c
index f5d17b6..cef3bc7 100644
--- a/src/gs-update-dialog.c
+++ b/src/gs-update-dialog.c
@@ -25,6 +25,7 @@
#include <gtk/gtk.h>
#include <packagekit-glib2/packagekit.h>
+#include "gs-cleanup.h"
#include "gs-update-dialog.h"
#include "gs-app-row.h"
#include "gs-markdown.h"
@@ -90,21 +91,19 @@ set_updates_description_ui (GsUpdateDialog *dialog, GsApp *app)
{
GsUpdateDialogPrivate *priv = gs_update_dialog_get_instance_private (dialog);
GsAppKind kind;
- GsMarkdown *markdown;
- gchar *tmp;
- gchar *update_desc;
const gchar *update_details;
+ _cleanup_free_ gchar *update_desc = NULL;
/* set window title */
kind = gs_app_get_kind (app);
if (kind == GS_APP_KIND_OS_UPDATE) {
gtk_window_set_title (GTK_WINDOW (dialog), gs_app_get_name (app));
} else {
+ _cleanup_free_ gchar *tmp = NULL;
tmp = g_strdup_printf ("%s %s",
- gs_app_get_source_default (app),
- gs_app_get_update_version (app));
+ gs_app_get_source_default (app),
+ gs_app_get_update_version (app));
gtk_window_set_title (GTK_WINDOW (dialog), tmp);
- g_free (tmp);
}
/* get the update description */
@@ -114,11 +113,11 @@ set_updates_description_ui (GsUpdateDialog *dialog, GsApp *app)
* description for the update */
update_desc = g_strdup (_("No update description available."));
} else {
+ _cleanup_object_unref_ GsMarkdown *markdown = NULL;
markdown = gs_markdown_new (GS_MARKDOWN_OUTPUT_PANGO);
gs_markdown_set_smart_quoting (markdown, FALSE);
gs_markdown_set_autocode (markdown, TRUE);
update_desc = gs_markdown_parse (markdown, update_details);
- g_object_unref (markdown);
}
/* set update header */
@@ -127,7 +126,6 @@ set_updates_description_ui (GsUpdateDialog *dialog, GsApp *app)
gs_image_set_from_pixbuf (GTK_IMAGE (priv->image_icon), gs_app_get_pixbuf (app));
gtk_label_set_label (GTK_LABEL (priv->label_name), gs_app_get_name (app));
gtk_label_set_label (GTK_LABEL (priv->label_summary), gs_app_get_summary (app));
- g_free (update_desc);
/* show the back button if needed */
gtk_widget_set_visible (priv->button_back, !g_queue_is_empty (priv->back_entry_stack));
@@ -135,8 +133,8 @@ set_updates_description_ui (GsUpdateDialog *dialog, GsApp *app)
static void
row_activated_cb (GtkListBox *list_box,
- GtkListBoxRow *row,
- GsUpdateDialog *dialog)
+ GtkListBoxRow *row,
+ GsUpdateDialog *dialog)
{
GsApp *app;
@@ -151,8 +149,8 @@ row_activated_cb (GtkListBox *list_box,
static void
installed_updates_row_activated_cb (GtkListBox *list_box,
- GtkListBoxRow *row,
- GsUpdateDialog *dialog)
+ GtkListBoxRow *row,
+ GsUpdateDialog *dialog)
{
GsApp *app;
@@ -178,8 +176,8 @@ gs_update_dialog_show_installed_updates (GsUpdateDialog *dialog, GList *installe
if (time_updates_installed > 0) {
GDateTime *date;
GtkWidget *header;
- gchar *date_str;
- gchar *subtitle;
+ _cleanup_free_ gchar *date_str = NULL;
+ _cleanup_free_ gchar *subtitle = NULL;
date = g_date_time_new_from_unix_utc (time_updates_installed);
date_str = g_date_time_format (date, "%x");
@@ -189,8 +187,6 @@ gs_update_dialog_show_installed_updates (GsUpdateDialog *dialog, GList *installe
subtitle = g_strdup_printf (_("Installed on %s"), date_str);
header = gtk_dialog_get_header_bar (GTK_DIALOG (dialog));
gtk_header_bar_set_subtitle (GTK_HEADER_BAR (header), subtitle);
-
- g_free (date_str);
}
gtk_widget_set_visible (priv->button_back, !g_queue_is_empty (priv->back_entry_stack));
@@ -199,7 +195,7 @@ gs_update_dialog_show_installed_updates (GsUpdateDialog *dialog, GList *installe
gs_container_remove_all (GTK_CONTAINER (priv->list_box_installed_updates));
for (l = installed_updates; l != NULL; l = l->next) {
gs_update_list_add_app (GS_UPDATE_LIST (priv->list_box_installed_updates),
- GS_APP (l->data));
+ GS_APP (l->data));
}
}
@@ -228,33 +224,33 @@ gs_update_dialog_show_update_details (GsUpdateDialog *dialog, GsApp *app)
app_related = g_ptr_array_index (related, i);
row = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
g_object_set_data_full (G_OBJECT (row),
- "app",
- g_object_ref (app_related),
- g_object_unref);
+ "app",
+ g_object_ref (app_related),
+ g_object_unref);
sort = gs_app_get_source_default (app_related);
g_object_set_data_full (G_OBJECT (row),
- "sort",
- g_strdup (sort),
- g_free);
+ "sort",
+ g_strdup (sort),
+ g_free);
label = gtk_label_new (gs_app_get_source_default (app_related));
g_object_set (label,
- "margin-start", 20,
- "margin-end", 20,
- "margin-top", 6,
- "margin-bottom", 6,
- "xalign", 0.0,
- NULL);
+ "margin-start", 20,
+ "margin-end", 20,
+ "margin-top", 6,
+ "margin-bottom", 6,
+ "xalign", 0.0,
+ NULL);
gtk_widget_set_halign (label, GTK_ALIGN_START);
gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
gtk_box_pack_start (GTK_BOX (row), label, TRUE, TRUE, 0);
label = gtk_label_new (gs_app_get_update_version (app_related));
g_object_set (label,
- "margin-start", 20,
- "margin-end", 20,
- "margin-top", 6,
- "margin-bottom", 6,
- "xalign", 1.0,
- NULL);
+ "margin-start", 20,
+ "margin-end", 20,
+ "margin-top", 6,
+ "margin-bottom", 6,
+ "xalign", 1.0,
+ NULL);
gtk_widget_set_halign (label, GTK_ALIGN_END);
gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
gtk_box_pack_start (GTK_BOX (row), label, FALSE, FALSE, 0);
@@ -269,8 +265,8 @@ gs_update_dialog_show_update_details (GsUpdateDialog *dialog, GsApp *app)
static void
list_header_func (GtkListBoxRow *row,
- GtkListBoxRow *before,
- gpointer user_data)
+ GtkListBoxRow *before,
+ gpointer user_data)
{
GtkWidget *header = NULL;
if (before != NULL)
@@ -280,8 +276,8 @@ list_header_func (GtkListBoxRow *row,
static gint
os_updates_sort_func (GtkListBoxRow *a,
- GtkListBoxRow *b,
- gpointer user_data)
+ GtkListBoxRow *b,
+ gpointer user_data)
{
GObject *o1 = G_OBJECT (gtk_bin_get_child (GTK_BIN (a)));
GObject *o2 = G_OBJECT (gtk_bin_get_child (GTK_BIN (b)));
@@ -361,20 +357,20 @@ gs_update_dialog_init (GsUpdateDialog *dialog)
priv->back_entry_stack = g_queue_new ();
g_signal_connect (GTK_LIST_BOX (priv->list_box), "row-activated",
- G_CALLBACK (row_activated_cb), dialog);
+ G_CALLBACK (row_activated_cb), dialog);
gtk_list_box_set_header_func (GTK_LIST_BOX (priv->list_box),
- list_header_func,
- dialog, NULL);
+ list_header_func,
+ dialog, NULL);
gtk_list_box_set_sort_func (GTK_LIST_BOX (priv->list_box),
- os_updates_sort_func,
- dialog, NULL);
+ os_updates_sort_func,
+ dialog, NULL);
g_signal_connect (GTK_LIST_BOX (priv->list_box_installed_updates), "row-activated",
G_CALLBACK (installed_updates_row_activated_cb), dialog);
g_signal_connect (priv->button_back, "clicked",
- G_CALLBACK (button_back_cb),
- dialog);
+ G_CALLBACK (button_back_cb),
+ dialog);
g_signal_connect_after (dialog, "show", G_CALLBACK (unset_focus), NULL);
@@ -414,8 +410,8 @@ GtkWidget *
gs_update_dialog_new (void)
{
return GTK_WIDGET (g_object_new (GS_TYPE_UPDATE_DIALOG,
- "use-header-bar", TRUE,
- NULL));
+ "use-header-bar", TRUE,
+ NULL));
}
/* vim: set noexpandtab: */
diff --git a/src/gs-update-list.c b/src/gs-update-list.c
index 2008ec1..733ba78 100644
--- a/src/gs-update-list.c
+++ b/src/gs-update-list.c
@@ -29,6 +29,7 @@
#include "gs-app.h"
#include "gs-app-row.h"
+#include "gs-cleanup.h"
struct _GsUpdateListPrivate
{
@@ -40,7 +41,7 @@ G_DEFINE_TYPE_WITH_PRIVATE (GsUpdateList, gs_update_list, GTK_TYPE_LIST_BOX)
void
gs_update_list_add_app (GsUpdateList *update_list,
- GsApp *app)
+ GsApp *app)
{
GsUpdateListPrivate *priv = gs_update_list_get_instance_private (update_list);
GtkWidget *app_row;
@@ -50,8 +51,8 @@ gs_update_list_add_app (GsUpdateList *update_list,
gs_app_row_set_app (GS_APP_ROW (app_row), app);
gtk_container_add (GTK_CONTAINER (update_list), app_row);
gs_app_row_set_size_groups (GS_APP_ROW (app_row),
- priv->sizegroup_image,
- priv->sizegroup_name);
+ priv->sizegroup_image,
+ priv->sizegroup_name);
gtk_widget_show (app_row);
}
@@ -69,8 +70,8 @@ is_addon_id_kind (GsApp *app)
static void
list_header_func (GtkListBoxRow *row,
- GtkListBoxRow *before,
- gpointer user_data)
+ GtkListBoxRow *before,
+ gpointer user_data)
{
GtkStyleContext *context;
GtkWidget *header;
@@ -87,8 +88,8 @@ list_header_func (GtkListBoxRow *row,
* applications and the addons */
header = gtk_label_new (_("Add-ons"));
g_object_set (header,
- "xalign", 0.0,
- NULL);
+ "xalign", 0.0,
+ NULL);
context = gtk_widget_get_style_context (header);
gtk_style_context_add_class (context, "header-label");
} else {
@@ -126,7 +127,7 @@ get_app_sort_key (GsApp *app)
/* sort by install date */
g_string_append_printf (key, "%09" G_GUINT64_FORMAT ":",
- G_MAXUINT64 - gs_app_get_install_date (app));
+ G_MAXUINT64 - gs_app_get_install_date (app));
/* finally, sort by short name */
g_string_append (key, gs_app_get_name (app));
@@ -135,22 +136,16 @@ get_app_sort_key (GsApp *app)
static gint
list_sort_func (GtkListBoxRow *a,
- GtkListBoxRow *b,
- gpointer user_data)
+ GtkListBoxRow *b,
+ gpointer user_data)
{
GsApp *a1 = gs_app_row_get_app (GS_APP_ROW (a));
GsApp *a2 = gs_app_row_get_app (GS_APP_ROW (b));
- gchar *key1 = get_app_sort_key (a1);
- gchar *key2 = get_app_sort_key (a2);
- gint retval;
+ _cleanup_free_ gchar *key1 = get_app_sort_key (a1);
+ _cleanup_free_ gchar *key2 = get_app_sort_key (a2);
/* compare the keys according to the algorithm above */
- retval = g_strcmp0 (key1, key2);
-
- g_free (key1);
- g_free (key2);
-
- return retval;
+ return g_strcmp0 (key1, key2);
}
static void
@@ -174,11 +169,11 @@ gs_update_list_init (GsUpdateList *update_list)
priv->sizegroup_name = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
gtk_list_box_set_header_func (GTK_LIST_BOX (update_list),
- list_header_func,
- update_list, NULL);
+ list_header_func,
+ update_list, NULL);
gtk_list_box_set_sort_func (GTK_LIST_BOX (update_list),
- list_sort_func,
- update_list, NULL);
+ list_sort_func,
+ update_list, NULL);
}
static void
diff --git a/src/gs-update-monitor.c b/src/gs-update-monitor.c
index 6693b79..6c92620 100644
--- a/src/gs-update-monitor.c
+++ b/src/gs-update-monitor.c
@@ -27,6 +27,7 @@
#include <packagekit-glib2/packagekit.h>
#include <gsettings-desktop-schemas/gdesktop-enums.h>
+#include "gs-cleanup.h"
#include "gs-update-monitor.h"
#include "gs-utils.h"
#include "gs-offline-updates.h"
@@ -41,7 +42,7 @@ struct _GsUpdateMonitor {
guint start_hourly_checks_id;
GDateTime *check_timestamp;
GDateTime *install_timestamp;
- gboolean refresh_cache_due;
+ gboolean refresh_cache_due;
gboolean get_updates_due;
gboolean network_available;
gchar **pending_downloads;
@@ -77,9 +78,9 @@ reenable_offline_update_notification (gpointer data)
static void
notify_offline_update_available (GsUpdateMonitor *monitor)
{
- GNotification *n;
const gchar *title;
const gchar *body;
+ _cleanup_object_unref_ GNotification *n = NULL;
if (!g_file_query_exists (monitor->offline_update_file, NULL))
return;
@@ -103,13 +104,12 @@ notify_offline_update_available (GsUpdateMonitor *monitor)
g_notification_add_button (n, _("Not Now"), "app.nop");
g_notification_set_default_action_and_target (n, "app.set-mode", "s", "updates");
g_application_send_notification (monitor->application, "updates-available", n);
- g_object_unref (n);
}
static void
offline_update_monitor_cb (GFileMonitor *file_monitor,
- GFile *file,
- GFile *other_file,
+ GFile *file,
+ GFile *other_file,
GFileMonitorEvent event_type,
GsUpdateMonitor *monitor)
{
@@ -131,9 +131,9 @@ show_installed_updates_notification (GsUpdateMonitor *monitor)
{
const gchar *message;
const gchar *title;
- GNotification *notification;
- GIcon *icon;
- PkResults *results;
+ _cleanup_object_unref_ GIcon *icon = NULL;
+ _cleanup_object_unref_ GNotification *notification = NULL;
+ _cleanup_object_unref_ PkResults *results = NULL;
results = pk_offline_get_results (NULL);
if (results == NULL)
@@ -160,7 +160,6 @@ show_installed_updates_notification (GsUpdateMonitor *monitor)
g_notification_set_body (notification, message);
icon = g_themed_icon_new ("gnome-software-symbolic");
g_notification_set_icon (notification, icon);
- g_object_unref (icon);
if (pk_results_get_exit_code (results) == PK_EXIT_ENUM_SUCCESS)
g_notification_add_button_with_target (notification, _("Review"), "app.set-mode", "s",
"updated");
else
@@ -168,8 +167,6 @@ show_installed_updates_notification (GsUpdateMonitor *monitor)
g_notification_add_button (notification, _("OK"), "app.clear-offline-updates");
g_application_send_notification (monitor->application, "offline-updates", notification);
- g_object_unref (notification);
- g_object_unref (results);
}
static gboolean
@@ -180,7 +177,7 @@ check_offline_update_cb (gpointer user_data)
guint64 time_update_completed;
g_settings_get (monitor->settings,
- "install-timestamp", "x", &time_last_notified);
+ "install-timestamp", "x", &time_last_notified);
time_update_completed = pk_offline_get_results_mtime (NULL);
if (time_update_completed > 0) {
@@ -188,14 +185,14 @@ check_offline_update_cb (gpointer user_data)
show_installed_updates_notification (monitor);
g_settings_set (monitor->settings,
- "install-timestamp", "x", time_update_completed);
+ "install-timestamp", "x", time_update_completed);
}
start_monitoring_offline_updates (monitor);
- monitor->check_offline_update_id = 0;
+ monitor->check_offline_update_id = 0;
- return G_SOURCE_REMOVE;
+ return G_SOURCE_REMOVE;
}
static gboolean
@@ -249,33 +246,27 @@ package_download_finished_cb (GObject *object,
gpointer data)
{
GsUpdateMonitor *monitor = data;
- PkResults *results;
- GError *error = NULL;
- PkError *error_code;
+ _cleanup_error_free_ GError *error = NULL;
+ _cleanup_object_unref_ PkError *error_code = NULL;
+ _cleanup_object_unref_ PkResults *results = NULL;
results = pk_client_generic_finish (PK_CLIENT (object), res, &error);
if (results == NULL) {
- if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
+ if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
g_warning ("failed to download: %s", error->message);
- }
- g_error_free (error);
return;
}
- error_code = pk_results_get_error_code (results);
- if (error_code != NULL) {
- g_warning ("failed to download: %s, %s",
- pk_error_enum_to_string (pk_error_get_code (error_code)),
- pk_error_get_details (error_code));
- g_object_unref (error_code);
- g_object_unref (results);
+ error_code = pk_results_get_error_code (results);
+ if (error_code != NULL) {
+ g_warning ("failed to download: %s, %s",
+ pk_error_enum_to_string (pk_error_get_code (error_code)),
+ pk_error_get_details (error_code));
return;
}
g_debug ("Downloaded updates");
-
g_clear_pointer (&monitor->pending_downloads, g_strfreev);
- g_object_unref (results);
}
static void
@@ -303,19 +294,17 @@ get_updates_finished_cb (GObject *object,
gpointer data)
{
GsUpdateMonitor *monitor = data;
- PkResults *results;
- PkError *error_code;
- GError *error = NULL;
- GPtrArray *packages;
guint i;
PkPackage *pkg;
+ _cleanup_error_free_ GError *error = NULL;
+ _cleanup_object_unref_ PkError *error_code = NULL;
+ _cleanup_object_unref_ PkResults *results = NULL;
+ _cleanup_ptrarray_unref_ GPtrArray *packages = NULL;
results = pk_client_generic_finish (PK_CLIENT (object), res, &error);
if (results == NULL) {
- if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
+ if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
g_warning ("failed to get updates: %s", error->message);
- }
- g_error_free (error);
return;
}
@@ -324,8 +313,6 @@ get_updates_finished_cb (GObject *object,
g_warning ("failed to get updates: %s, %s",
pk_error_enum_to_string (pk_error_get_code (error_code)),
pk_error_get_details (error_code));
- g_object_unref (error_code);
- g_object_unref (results);
return;
}
@@ -348,9 +335,6 @@ get_updates_finished_cb (GObject *object,
download_updates (monitor);
}
-
- g_ptr_array_unref (packages);
- g_object_unref (results);
}
static void
@@ -378,16 +362,14 @@ refresh_cache_finished_cb (GObject *object,
gpointer data)
{
GsUpdateMonitor *monitor = data;
- PkResults *results;
- PkError *error_code;
- GError *error = NULL;
+ _cleanup_error_free_ GError *error = NULL;
+ _cleanup_object_unref_ PkError *error_code = NULL;
+ _cleanup_object_unref_ PkResults *results = NULL;
results = pk_client_generic_finish (PK_CLIENT (object), res, &error);
if (results == NULL) {
- if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
+ if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
g_warning ("failed to refresh the cache: %s", error->message);
- }
- g_error_free (error);
return;
}
@@ -396,15 +378,11 @@ refresh_cache_finished_cb (GObject *object,
g_warning ("failed to refresh the cache: %s, %s",
pk_error_enum_to_string (pk_error_get_code (error_code)),
pk_error_get_details (error_code));
- g_object_unref (error_code);
- g_object_unref (results);
return;
}
monitor->refresh_cache_due = FALSE;
- g_object_unref (results);
-
get_updates (monitor);
}
@@ -418,7 +396,6 @@ refresh_cache (GsUpdateMonitor *monitor)
return;
g_debug ("Refreshing cache");
-
pk_client_refresh_cache_async (PK_CLIENT (monitor->task),
TRUE,
monitor->cancellable,
@@ -547,7 +524,7 @@ gs_update_monitor_init (GsUpdateMonitor *monitor)
"only-download", TRUE,
NULL);
- monitor->network_available = FALSE;
+ monitor->network_available = FALSE;
monitor->control = pk_control_new ();
g_signal_connect (monitor->control, "notify::network-state",
G_CALLBACK (notify_network_state_cb), monitor);
@@ -604,9 +581,9 @@ remove_stale_notifications (GsUpdateMonitor *monitor)
g_debug ("Withdrawing stale notifications");
g_application_withdraw_notification (monitor->application,
- "updates-available");
+ "updates-available");
g_application_withdraw_notification (monitor->application,
- "offline-updates");
+ "offline-updates");
}
}
diff --git a/src/gs-utils.c b/src/gs-utils.c
index f12bb3f..a76d5d3 100644
--- a/src/gs-utils.c
+++ b/src/gs-utils.c
@@ -26,6 +26,7 @@
#include <errno.h>
#include "gs-app.h"
+#include "gs-cleanup.h"
#include "gs-utils.h"
#include "gs-plugin.h"
@@ -127,8 +128,8 @@ gs_grab_focus_when_mapped (GtkWidget *widget)
void
gs_app_notify_installed (GsApp *app)
{
- gchar *summary;
- GNotification *n;
+ _cleanup_free_ gchar *summary = NULL;
+ _cleanup_object_unref_ GNotification *n = NULL;
/* TRANSLATORS: this is the summary of a notification that an application
* has been successfully installed */
@@ -143,8 +144,6 @@ gs_app_notify_installed (GsApp *app)
g_notification_set_default_action_and_target (n, "app.details", "(ss)",
gs_app_get_id (app), "");
g_application_send_notification (g_application_get_default (), "installed", n);
- g_object_unref (n);
- g_free (summary);
}
/**
@@ -157,8 +156,8 @@ gs_app_notify_failed_modal (GsApp *app,
const GError *error)
{
GtkWidget *dialog;
- gchar *title;
- gchar *msg;
+ const gchar *title;
+ _cleanup_free_ gchar *msg = NULL;
title = _("Sorry, this did not work");
switch (action) {
@@ -352,39 +351,34 @@ out:
gboolean
gs_mkdir_parent (const gchar *path, GError **error)
{
- gboolean ret = TRUE;
- gchar *parent;
+ _cleanup_free_ gchar *parent = NULL;
parent = g_path_get_dirname (path);
if (g_mkdir_with_parents (parent, 0755) == -1) {
- ret = FALSE;
g_set_error (error,
GS_PLUGIN_ERROR,
GS_PLUGIN_ERROR_FAILED,
"Failed to create '%s': %s",
parent, g_strerror (errno));
+ return FALSE;
}
-
- g_free (parent);
- return ret;
+ return TRUE;
}
static void
reboot_done (GObject *source, GAsyncResult *res, gpointer data)
{
GCallback reboot_failed = data;
- GVariant *ret;
- GError *error = NULL;
+ _cleanup_variant_unref_ GVariant *ret = NULL;
+ _cleanup_error_free_ GError *error = NULL;
ret = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source), res, &error);
- if (ret) {
- g_variant_unref (ret);
+ if (ret)
return;
- }
- if (error) {
- g_warning ("Calling org.gnome.SessionManager.Reboot failed: %s", error->message);
- g_error_free (error);
+ if (error != NULL) {
+ g_warning ("Calling org.gnome.SessionManager.Reboot failed: %s",
+ error->message);
}
reboot_failed ();
@@ -393,7 +387,7 @@ reboot_done (GObject *source, GAsyncResult *res, gpointer data)
void
gs_reboot (GCallback reboot_failed)
{
- GDBusConnection *bus;
+ _cleanup_object_unref_ GDBusConnection *bus = NULL;
g_debug ("calling org.gnome.SessionManager.Reboot");
@@ -410,7 +404,6 @@ gs_reboot (GCallback reboot_failed)
NULL,
reboot_done,
reboot_failed);
- g_object_unref (bus);
}
/**
diff --git a/src/plugins/gs-moduleset.c b/src/plugins/gs-moduleset.c
index 26701d8..a1c5a49 100644
--- a/src/plugins/gs-moduleset.c
+++ b/src/plugins/gs-moduleset.c
@@ -24,6 +24,7 @@
#include <string.h>
#include <glib.h>
+#include "gs-cleanup.h"
#include "gs-moduleset.h"
typedef struct {
@@ -235,8 +236,8 @@ gs_moduleset_parse_filename (GsModuleset *moduleset, const gchar *filename, GErr
NULL };
GMarkupParseContext *ctx;
gboolean ret;
- gchar *data = NULL;
gsize data_len;
+ _cleanup_free_ gchar *data = NULL;
g_return_val_if_fail (GS_IS_MODULESET (moduleset), FALSE);
@@ -252,7 +253,6 @@ gs_moduleset_parse_filename (GsModuleset *moduleset, const gchar *filename, GErr
goto out;
out:
g_markup_parse_context_free (ctx);
- g_free (data);
return ret;
}
@@ -262,30 +262,22 @@ out:
gboolean
gs_moduleset_parse_path (GsModuleset *moduleset, const gchar *path, GError **error)
{
- GDir *dir;
- gboolean ret = TRUE;
const gchar *filename;
- gchar *tmp;
+ _cleanup_dir_close_ GDir *dir = NULL;
/* search all the files in the path */
dir = g_dir_open (path, 0, error);
- if (dir == NULL) {
- ret = FALSE;
- goto out;
- }
+ if (dir == NULL)
+ return FALSE;
while ((filename = g_dir_read_name (dir)) != NULL) {
+ _cleanup_free_ gchar *tmp = NULL;
if (!g_str_has_suffix (filename, ".xml"))
continue;
tmp = g_build_filename (path, filename, NULL);
- ret = gs_moduleset_parse_filename (moduleset, tmp, error);
- g_free (tmp);
- if (!ret)
- goto out;
+ if (!gs_moduleset_parse_filename (moduleset, tmp, error))
+ return FALSE;
}
-out:
- if (dir != NULL)
- g_dir_close (dir);
- return ret;
+ return TRUE;
}
static void
diff --git a/src/plugins/gs-plugin-appstream.c b/src/plugins/gs-plugin-appstream.c
index 44984a5..f800661 100644
--- a/src/plugins/gs-plugin-appstream.c
+++ b/src/plugins/gs-plugin-appstream.c
@@ -132,12 +132,12 @@ gs_plugin_appstream_get_origins_hash (GPtrArray *array)
{
AsApp *app;
GHashTable *origins = NULL;
- GList *keys = NULL;
GList *l;
const gchar *tmp;
gdouble perc;
guint *cnt;
guint i;
+ _cleanup_list_free_ GList *keys = NULL;
/* create a hash table with origin:cnt */
origins = g_hash_table_new_full (g_str_hash, g_str_equal,
@@ -165,7 +165,6 @@ gs_plugin_appstream_get_origins_hash (GPtrArray *array)
*cnt = perc;
}
- g_list_free (keys);
return origins;
}
@@ -176,13 +175,13 @@ static gboolean
gs_plugin_startup (GsPlugin *plugin, GError **error)
{
AsApp *app;
- GHashTable *origins = NULL;
GPtrArray *items;
gboolean ret;
const gchar *origin;
gchar *tmp;
guint *perc;
guint i;
+ _cleanup_hashtable_unref_ GHashTable *origins = NULL;
/* clear all existing applications if the store was invalidated */
as_store_remove_all (plugin->priv->store);
@@ -244,8 +243,6 @@ gs_plugin_startup (GsPlugin *plugin, GError **error)
}
}
out:
- if (origins != NULL)
- g_hash_table_unref (origins);
gs_profile_stop (plugin->profile, "appstream::startup");
return ret;
}
@@ -257,10 +254,10 @@ static void
gs_plugin_refine_item_pixbuf (GsPlugin *plugin, GsApp *app, AsApp *item)
{
AsIcon *icon;
- GError *error = NULL;
gboolean ret;
- gchar *fn = NULL;
- gchar *path = NULL;
+ _cleanup_error_free_ GError *error = NULL;
+ _cleanup_free_ gchar *fn = NULL;
+ _cleanup_free_ gchar *path = NULL;
icon = as_app_get_icon_default (item);
switch (as_icon_get_kind (icon)) {
@@ -280,8 +277,7 @@ gs_plugin_refine_item_pixbuf (GsPlugin *plugin, GsApp *app, AsApp *item)
g_warning ("failed to load icon %s: %s",
as_icon_get_name (icon),
error->message);
- g_error_free (error);
- goto out;
+ return;
}
}
break;
@@ -301,8 +297,7 @@ gs_plugin_refine_item_pixbuf (GsPlugin *plugin, GsApp *app, AsApp *item)
as_icon_kind_to_string (as_icon_get_kind (icon)),
as_icon_get_name (icon),
error->message);
- g_error_free (error);
- return;
+ return;
}
break;
case AS_ICON_KIND_CACHED:
@@ -318,8 +313,7 @@ gs_plugin_refine_item_pixbuf (GsPlugin *plugin, GsApp *app, AsApp *item)
if (!as_icon_load (icon, AS_ICON_LOAD_FLAG_SEARCH_SIZE, &error)) {
g_warning ("failed to load cached icon %s: %s",
as_icon_get_name (icon), error->message);
- g_error_free (error);
- return;
+ return;
}
gs_app_set_pixbuf (app, as_icon_get_pixbuf (icon));
break;
@@ -327,9 +321,6 @@ gs_plugin_refine_item_pixbuf (GsPlugin *plugin, GsApp *app, AsApp *item)
g_warning ("icon kind unknown for %s", as_app_get_id (item));
break;
}
-out:
- g_free (path);
- g_free (fn);
}
/**
@@ -347,23 +338,17 @@ gs_plugin_refine_add_addons (GsPlugin *plugin, GsApp *app, AsApp *item)
for (i = 0; i < addons->len; i++) {
AsApp *as_addon = g_ptr_array_index (addons, i);
- GsApp *addon;
- GError *error = NULL;
- gboolean ret;
+ _cleanup_error_free_ GError *error = NULL;
+ _cleanup_object_unref_ GsApp *addon = NULL;
addon = gs_app_new (as_app_get_id (as_addon));
/* add all the data we can */
- ret = gs_plugin_refine_item (plugin, addon, as_addon, &error);
- if (!ret) {
+ if (!gs_plugin_refine_item (plugin, addon, as_addon, &error)) {
g_warning ("failed to refine addon: %s", error->message);
- g_error_free (error);
- g_object_unref (addon);
continue;
}
-
gs_app_add_addon (app, addon);
- g_object_unref (addon);
}
}
/**
@@ -406,9 +391,9 @@ gs_plugin_refine_add_screenshots (GsApp *app, AsApp *item)
static void
gs_plugin_appstream_set_license (GsApp *app, const gchar *license_string)
{
- GString *urld;
- gchar **tokens;
guint i;
+ _cleanup_string_free_ GString *urld = NULL;
+ _cleanup_strv_free_ gchar **tokens = NULL;
/* tokenize the license string and URLify any SPDX IDs */
urld = g_string_sized_new (strlen (license_string) + 1);
@@ -459,8 +444,6 @@ gs_plugin_appstream_set_license (GsApp *app, const gchar *license_string)
g_string_append (urld, tokens[i]);
}
gs_app_set_licence (app, urld->str);
- g_strfreev (tokens);
- g_string_free (urld, TRUE);
}
/**
@@ -540,8 +523,6 @@ gs_plugin_refine_item (GsPlugin *plugin,
GPtrArray *pkgnames;
GPtrArray *kudos;
const gchar *tmp;
- gboolean ret = TRUE;
- gchar *from_xml;
guint i;
/* is an app */
@@ -599,15 +580,14 @@ gs_plugin_refine_item (GsPlugin *plugin,
urls = as_app_get_urls (item);
if (g_hash_table_size (urls) > 0 &&
gs_app_get_url (app, AS_URL_KIND_HOMEPAGE) == NULL) {
- GList *keys;
GList *l;
+ _cleanup_list_free_ GList *keys = NULL;
keys = g_hash_table_get_keys (urls);
for (l = keys; l != NULL; l = l->next) {
gs_app_set_url (app,
as_url_kind_from_string (l->data),
g_hash_table_lookup (urls, l->data));
}
- g_list_free (keys);
}
/* set licence */
@@ -624,16 +604,15 @@ gs_plugin_refine_item (GsPlugin *plugin,
/* set description */
tmp = as_app_get_description (item, NULL);
if (tmp != NULL) {
+ _cleanup_free_ gchar *from_xml = NULL;
from_xml = as_markup_convert_simple (tmp, -1, error);
if (from_xml == NULL) {
g_prefix_error (error, "trying to parse '%s': ", tmp);
- ret = FALSE;
- goto out;
+ return FALSE;
}
gs_app_set_description (app,
GS_APP_QUALITY_HIGHEST,
from_xml);
- g_free (from_xml);
}
/* set icon */
@@ -726,8 +705,7 @@ gs_plugin_refine_item (GsPlugin *plugin,
break;
}
}
-out:
- return ret;
+ return TRUE;
}
/**
@@ -771,7 +749,6 @@ gs_plugin_refine_from_pkgname (GsPlugin *plugin,
AsApp *item = NULL;
GPtrArray *sources;
const gchar *pkgname;
- gboolean ret = TRUE;
guint i;
/* find anything that matches the ID */
@@ -786,14 +763,10 @@ gs_plugin_refine_from_pkgname (GsPlugin *plugin,
/* nothing found */
if (item == NULL)
- goto out;
+ return TRUE;
/* set new properties */
- ret = gs_plugin_refine_item (plugin, app, item, error);
- if (!ret)
- goto out;
-out:
- return ret;
+ return gs_plugin_refine_item (plugin, app, item, error);
}
/**
@@ -852,7 +825,6 @@ gs_plugin_add_category_apps (GsPlugin *plugin,
const gchar *search_id1;
const gchar *search_id2 = NULL;
gboolean ret = TRUE;
- GsApp *app;
AsApp *item;
GsCategory *parent;
GPtrArray *array;
@@ -882,6 +854,7 @@ gs_plugin_add_category_apps (GsPlugin *plugin,
/* just look at each app in turn */
array = as_store_get_apps (plugin->priv->store);
for (i = 0; i < array->len; i++) {
+ _cleanup_object_unref_ GsApp *app = NULL;
item = g_ptr_array_index (array, i);
if (as_app_get_id (item) == NULL)
continue;
@@ -896,7 +869,6 @@ gs_plugin_add_category_apps (GsPlugin *plugin,
if (!ret)
goto out;
gs_plugin_add_app (list, app);
- g_object_unref (app);
}
out:
gs_profile_stop (plugin->profile, "appstream::add-category-apps");
@@ -913,15 +885,12 @@ gs_plugin_add_search_item_add (GsPlugin *plugin,
guint match_value,
GError **error)
{
- GsApp *app;
+ _cleanup_object_unref_ GsApp *app = NULL;
app = gs_app_new (as_app_get_id (item));
- if (!gs_plugin_refine_item (plugin, app, item, error)) {
- g_object_unref (app);
+ if (!gs_plugin_refine_item (plugin, app, item, error))
return FALSE;
- }
gs_app_set_search_sort_key (app, match_value);
gs_plugin_add_app (list, app);
- g_object_unref (app);
return TRUE;
}
@@ -1032,7 +1001,6 @@ gs_plugin_add_installed (GsPlugin *plugin,
AsApp *item;
gboolean ret = TRUE;
GPtrArray *array;
- GsApp *app;
guint i;
/* load XML files */
@@ -1049,12 +1017,12 @@ gs_plugin_add_installed (GsPlugin *plugin,
for (i = 0; i < array->len; i++) {
item = g_ptr_array_index (array, i);
if (as_app_get_source_kind (item) == AS_APP_SOURCE_KIND_APPDATA) {
+ _cleanup_object_unref_ GsApp *app = NULL;
app = gs_app_new (as_app_get_id (item));
ret = gs_plugin_refine_item (plugin, app, item, error);
if (!ret)
goto out;
gs_plugin_add_app (list, app);
- g_object_unref (app);
}
}
out:
@@ -1068,7 +1036,6 @@ out:
static void
gs_plugin_add_categories_for_app (GList *list, AsApp *app)
{
- GList *children;
GList *l;
GList *l2;
GsCategory *category;
@@ -1077,6 +1044,7 @@ gs_plugin_add_categories_for_app (GList *list, AsApp *app)
/* does it match the main category */
for (l = list; l != NULL; l = l->next) {
+ _cleanup_list_free_ GList *children = NULL;
parent = GS_CATEGORY (l->data);
if (!as_app_has_category (app, gs_category_get_id (parent)))
continue;
@@ -1092,7 +1060,6 @@ gs_plugin_add_categories_for_app (GList *list, AsApp *app)
gs_category_increment_size (category);
found_subcat = TRUE;
}
- g_list_free (children);
/* matching the main category but no subcategories means we have
* to create a new 'Other' subcategory manually */
@@ -1173,12 +1140,12 @@ gs_plugin_add_popular_from_category (GsPlugin *plugin,
AsApp *item;
GError *error_local = NULL;
GPtrArray *array;
- GsApp *app;
guint i;
/* search categories for the search term */
array = as_store_get_apps (plugin->priv->store);
for (i = 0; i < array->len; i++) {
+ _cleanup_object_unref_ GsApp *app = NULL;
item = g_ptr_array_index (array, i);
/* find not-installed desktop application with long descriptions
@@ -1206,7 +1173,6 @@ gs_plugin_add_popular_from_category (GsPlugin *plugin,
as_app_get_id (item),
error_local->message);
g_clear_error (&error_local);
- g_object_unref (app);
continue;
}
@@ -1219,7 +1185,6 @@ gs_plugin_add_popular_from_category (GsPlugin *plugin,
(gpointer) as_app_get_id (item),
GINT_TO_POINTER (1));
}
- g_object_unref (app);
}
return TRUE;
}
@@ -1236,13 +1201,13 @@ gs_plugin_add_popular_by_cat (GsPlugin *plugin,
GError **error)
{
AsApp *item;
- GHashTable *ignore_cats = NULL;
GPtrArray *array;
GPtrArray *categories;
const gchar *tmp;
gboolean ret = TRUE;
guint i;
guint j;
+ _cleanup_hashtable_unref_ GHashTable *ignore_cats = NULL;
/* ignore main categories */
gs_profile_start (plugin->profile, "appstream::add_popular[cat]");
@@ -1299,8 +1264,6 @@ gs_plugin_add_popular_by_cat (GsPlugin *plugin,
}
out:
gs_profile_stop (plugin->profile, "appstream::add_popular[cat]");
- if (ignore_cats != NULL)
- g_hash_table_unref (ignore_cats);
return ret;
}
@@ -1314,11 +1277,10 @@ gs_plugin_add_popular_by_source (GsPlugin *plugin,
GError **error)
{
AsApp *item;
- GHashTable *installed = NULL; /* source_pkgname : AsApp */
GPtrArray *array;
- GsApp *app;
gboolean ret = TRUE;
guint i;
+ _cleanup_hashtable_unref_ GHashTable *installed = NULL; /* srcpkg : AsApp */
/* get already installed applications */
gs_profile_start (plugin->profile, "appstream::add_popular[source]");
@@ -1339,6 +1301,7 @@ gs_plugin_add_popular_by_source (GsPlugin *plugin,
/* search categories for the search term */
for (i = 0; i < array->len; i++) {
+ _cleanup_object_unref_ GsApp *app = NULL;
item = g_ptr_array_index (array, i);
/* find not installed desktop applications */
@@ -1369,12 +1332,9 @@ gs_plugin_add_popular_by_source (GsPlugin *plugin,
g_debug ("not suggesting %s as not awesome enough",
as_app_get_id (item));
}
- g_object_unref (app);
}
out:
gs_profile_stop (plugin->profile, "appstream::add_popular[source]");
- if (installed != NULL)
- g_hash_table_unref (installed);
return ret;
}
@@ -1390,10 +1350,10 @@ gs_plugin_add_popular (GsPlugin *plugin,
GError **error)
{
AsApp *item;
- GHashTable *ignore_apps = NULL;
GPtrArray *array;
gboolean ret = TRUE;
guint i;
+ _cleanup_keyfile_unref_ GHashTable *ignore_apps = NULL;
/* load XML files */
if (g_once_init_enter (&plugin->priv->done_init)) {
@@ -1444,7 +1404,5 @@ gs_plugin_add_popular (GsPlugin *plugin,
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-fedora-tagger-ratings.c b/src/plugins/gs-plugin-fedora-tagger-ratings.c
index d037b5c..675148c 100644
--- a/src/plugins/gs-plugin-fedora-tagger-ratings.c
+++ b/src/plugins/gs-plugin-fedora-tagger-ratings.c
@@ -108,13 +108,13 @@ gs_plugin_destroy (GsPlugin *plugin)
static gchar *
gs_plugin_parse_json (const gchar *data, gsize data_len, const gchar *key)
{
- GString *string;
gchar *key_full;
gchar *value = NULL;
- gchar **split;
guint i;
gchar *tmp;
guint len;
+ _cleanup_string_free_ GString *string = NULL;
+ _cleanup_strv_free_ gchar **split = NULL;
/* format the key to match what JSON returns */
key_full = g_strdup_printf ("\"%s\":", key);
@@ -144,8 +144,6 @@ gs_plugin_parse_json (const gchar *data, gsize data_len, const gchar *key)
value = g_strndup (tmp, len);
}
}
- g_strfreev (split);
- g_string_free (string, TRUE);
return value;
}
@@ -156,11 +154,9 @@ gs_plugin_parse_json (const gchar *data, gsize data_len, const gchar *key)
static gboolean
gs_plugin_setup_networking (GsPlugin *plugin, GError **error)
{
- gboolean ret = TRUE;
-
/* already set up */
if (plugin->priv->session != NULL)
- goto out;
+ return TRUE;
/* set up a session */
plugin->priv->session = soup_session_sync_new_with_options (SOUP_SESSION_USER_AGENT,
@@ -168,18 +164,16 @@ gs_plugin_setup_networking (GsPlugin *plugin, GError **error)
SOUP_SESSION_TIMEOUT, 5000,
NULL);
if (plugin->priv->session == NULL) {
- ret = FALSE;
g_set_error (error,
GS_PLUGIN_ERROR,
GS_PLUGIN_ERROR_FAILED,
"%s: failed to setup networking",
plugin->name);
- goto out;
+ return FALSE;
}
soup_session_add_feature_by_type (plugin->priv->session,
SOUP_TYPE_PROXY_RESOLVER_DEFAULT);
-out:
- return ret;
+ return TRUE;
}
/**
@@ -191,11 +185,11 @@ gs_plugin_app_set_rating_pkg (GsPlugin *plugin,
gint rating,
GError **error)
{
- SoupMessage *msg = NULL;
- gchar *data = NULL;
- gchar *error_msg = NULL;
- gchar *uri = NULL;
guint status_code;
+ _cleanup_free_ gchar *data = NULL;
+ _cleanup_free_ gchar *error_msg = NULL;
+ _cleanup_free_ gchar *uri = NULL;
+ _cleanup_object_unref_ SoupMessage *msg = NULL;
/* create the PUT data */
uri = g_strdup_printf ("%s/api/v1/rating/%s/",
@@ -220,12 +214,6 @@ gs_plugin_app_set_rating_pkg (GsPlugin *plugin,
} else {
g_debug ("Got response: %s", msg->response_body->data);
}
-
- g_free (error_msg);
- g_free (data);
- g_free (uri);
- if (msg != NULL)
- g_object_unref (msg);
return TRUE;
}
@@ -240,20 +228,19 @@ gs_plugin_app_set_rating (GsPlugin *plugin,
{
GPtrArray *sources;
const gchar *pkgname;
- gboolean ret = TRUE;
+ gboolean ret;
guint i;
/* get the package name */
sources = gs_app_get_sources (app);
if (sources->len == 0) {
g_warning ("no pkgname for %s", gs_app_get_id (app));
- goto out;
+ return TRUE;
}
/* ensure networking is set up */
- ret = gs_plugin_setup_networking (plugin, error);
- if (!ret)
- goto out;
+ if (!gs_plugin_setup_networking (plugin, error))
+ return FALSE;
/* set rating for each package */
for (i = 0; i < sources->len; i++) {
@@ -263,10 +250,9 @@ gs_plugin_app_set_rating (GsPlugin *plugin,
gs_app_get_rating (app),
error);
if (!ret)
- goto out;
+ return FALSE;
}
-out:
- return ret;
+ return TRUE;
}
/**
@@ -307,10 +293,9 @@ gs_plugin_fedora_tagger_add (GsPlugin *plugin,
FedoraTaggerItem *item,
GError **error)
{
- gboolean ret = TRUE;
- gchar *error_msg = NULL;
- gchar *statement = NULL;
+ char *error_msg = NULL;
gint rc;
+ _cleanup_free_ gchar *statement = NULL;
/* insert the entry */
statement = g_strdup_printf ("INSERT OR REPLACE INTO ratings (pkgname, rating, "
@@ -326,12 +311,9 @@ gs_plugin_fedora_tagger_add (GsPlugin *plugin,
GS_PLUGIN_ERROR_FAILED,
"SQL error: %s", error_msg);
sqlite3_free (error_msg);
- ret = FALSE;
- goto out;
+ return FALSE;
}
-out:
- g_free (statement);
- return ret;
+ return TRUE;
}
@@ -343,10 +325,9 @@ gs_plugin_fedora_tagger_set_timestamp (GsPlugin *plugin,
const gchar *type,
GError **error)
{
- gboolean ret = TRUE;
- gchar *error_msg = NULL;
- gchar *statement = NULL;
+ char *error_msg = NULL;
gint rc;
+ _cleanup_free_ gchar *statement = NULL;
/* insert the entry */
statement = g_strdup_printf ("INSERT OR REPLACE INTO timestamps (key, value) "
@@ -360,13 +341,9 @@ gs_plugin_fedora_tagger_set_timestamp (GsPlugin *plugin,
GS_PLUGIN_ERROR_FAILED,
"SQL error: %s", error_msg);
sqlite3_free (error_msg);
- ret = FALSE;
- goto out;
+ return FALSE;
}
-out:
- g_free (statement);
- return ret;
-
+ return TRUE;
}
/**
@@ -376,16 +353,13 @@ static gboolean
gs_plugin_fedora_tagger_download (GsPlugin *plugin, GError **error)
{
FedoraTaggerItem *item;
- GPtrArray *items = NULL;
- SoupMessage *msg = NULL;
- gboolean ret = TRUE;
- gchar *error_msg = NULL;
- gchar **fields;
- gchar **split = NULL;
- gchar *uri = NULL;
gdouble count_sum = 0;
guint i;
guint status_code;
+ _cleanup_free_ gchar *uri = NULL;
+ _cleanup_free_ SoupMessage *msg = NULL;
+ _cleanup_ptrarray_unref_ GPtrArray *items = NULL;
+ _cleanup_strv_free_ gchar **split = NULL;
/* create the GET data */
uri = g_strdup_printf ("%s/api/v1/rating/dump/",
@@ -393,26 +367,25 @@ gs_plugin_fedora_tagger_download (GsPlugin *plugin, GError **error)
msg = soup_message_new (SOUP_METHOD_GET, uri);
/* ensure networking is set up */
- ret = gs_plugin_setup_networking (plugin, error);
- if (!ret)
- goto out;
+ if (!gs_plugin_setup_networking (plugin, error))
+ return FALSE;
/* set sync request */
status_code = soup_session_send_message (plugin->priv->session, msg);
if (status_code != SOUP_STATUS_OK) {
- ret = FALSE;
g_set_error (error,
GS_PLUGIN_ERROR,
GS_PLUGIN_ERROR_FAILED,
"Failed to download fedora-tagger dump: %s",
soup_status_get_phrase (status_code));
- goto out;
+ return FALSE;
}
/* process the tab-delimited data */
items = g_ptr_array_new_with_free_func ((GDestroyNotify) fedora_tagger_item_free);
split = g_strsplit (msg->response_body->data, "\n", -1);
for (i = 0; split[i] != NULL; i++) {
+ _cleanup_strv_free_ gchar **fields = NULL;
if (split[i][0] == '\0' ||
split[i][0] == '#')
continue;
@@ -429,17 +402,15 @@ gs_plugin_fedora_tagger_download (GsPlugin *plugin, GError **error)
"'pkgname\trating\tvote_count\tuser_count' and got '%s'",
split[i]);
}
- g_strfreev (fields);
}
/* no suitable data? */
if (items->len == 0) {
- ret = FALSE;
g_set_error_literal (error,
GS_PLUGIN_ERROR,
GS_PLUGIN_ERROR_FAILED,
"Failed to get data from fedora-tagger");
- goto out;
+ return FALSE;
}
/* calculate confidence */
@@ -448,12 +419,11 @@ gs_plugin_fedora_tagger_download (GsPlugin *plugin, GError **error)
count_sum += item->vote_count;
}
if (count_sum == 0) {
- ret = FALSE;
g_set_error_literal (error,
GS_PLUGIN_ERROR,
GS_PLUGIN_ERROR_FAILED,
"Failed to get vote count in fedora-tagger");
- goto out;
+ return FALSE;
}
count_sum /= (gdouble) items->len;
g_debug ("fedora-tagger vote_count average is %.2f", count_sum);
@@ -468,24 +438,12 @@ gs_plugin_fedora_tagger_download (GsPlugin *plugin, GError **error)
g_debug ("adding %s: %.1f%% [%.1f] {%.1f%%}",
item->pkgname, item->rating,
item->vote_count, item->confidence);
- ret = gs_plugin_fedora_tagger_add (plugin, item, error);
- if (!ret)
- goto out;
+ if (!gs_plugin_fedora_tagger_add (plugin, item, error))
+ return FALSE;
}
/* reset the timestamp */
- ret = gs_plugin_fedora_tagger_set_timestamp (plugin, "mtime", error);
- if (!ret)
- goto out;
-out:
- g_free (error_msg);
- g_free (uri);
- g_strfreev (split);
- if (items != NULL)
- g_ptr_array_unref (items);
- if (msg != NULL)
- g_object_unref (msg);
- return ret;
+ return gs_plugin_fedora_tagger_set_timestamp (plugin, "mtime", error);
}
/**
@@ -494,28 +452,25 @@ out:
static gboolean
gs_plugin_fedora_tagger_load_db (GsPlugin *plugin, GError **error)
{
- GError *error_local = NULL;
const gchar *statement;
- gboolean ret = TRUE;
gboolean rebuild_ratings = FALSE;
- gchar *error_msg = NULL;
+ char *error_msg = NULL;
gint rc;
gint64 mtime = 0;
gint64 now;
+ _cleanup_error_free_ GError *error_local = NULL;
g_debug ("trying to open database '%s'", plugin->priv->db_path);
- ret = gs_mkdir_parent (plugin->priv->db_path, error);
- if (!ret)
- goto out;
+ if (!gs_mkdir_parent (plugin->priv->db_path, error))
+ return FALSE;
rc = sqlite3_open (plugin->priv->db_path, &plugin->priv->db);
if (rc != SQLITE_OK) {
- ret = FALSE;
g_set_error (error,
GS_PLUGIN_ERROR,
GS_PLUGIN_ERROR_FAILED,
"Can't open fedora-tagger database: %s",
sqlite3_errmsg (plugin->priv->db));
- goto out;
+ return FALSE;
}
/* we don't need to keep doing fsync */
@@ -556,9 +511,8 @@ gs_plugin_fedora_tagger_load_db (GsPlugin *plugin, GError **error)
sqlite3_exec (plugin->priv->db, statement, NULL, NULL, NULL);
/* reset the timestamp */
- ret = gs_plugin_fedora_tagger_set_timestamp (plugin, "ctime", error);
- if (!ret)
- goto out;
+ if (!gs_plugin_fedora_tagger_set_timestamp (plugin, "ctime", error))
+ return FALSE;
}
/* no data */
@@ -569,23 +523,20 @@ gs_plugin_fedora_tagger_load_db (GsPlugin *plugin, GError **error)
if (!gs_plugin_fedora_tagger_download (plugin, &error_local)) {
g_warning ("Failed to get fedora-tagger data: %s",
error_local->message);
- g_error_free (error_local);
- goto out;
+ return TRUE;
}
} else if (now - mtime > GS_PLUGIN_FEDORA_TAGGER_AGE_MAX) {
g_debug ("fedora-tagger data was %" G_GINT64_FORMAT
" days old, so regetting",
(now - mtime) / ( 60 * 60 * 24));
- ret = gs_plugin_fedora_tagger_download (plugin, error);
- if (!ret)
- goto out;
+ if (!gs_plugin_fedora_tagger_download (plugin, error))
+ return FALSE;
} else {
g_debug ("fedora-tagger data %" G_GINT64_FORMAT
" days old, so no need to redownload",
(now - mtime) / ( 60 * 60 * 24));
}
-out:
- return ret;
+ return TRUE;
}
typedef struct {
@@ -619,10 +570,9 @@ gs_plugin_resolve_app (GsPlugin *plugin,
GError **error)
{
FedoraTaggerHelper helper;
- gboolean ret = TRUE;
gchar *error_msg = NULL;
- gchar *statement;
gint rc;
+ _cleanup_free_ gchar *statement = NULL;
/* default values */
helper.rating = -1;
@@ -642,8 +592,7 @@ gs_plugin_resolve_app (GsPlugin *plugin,
GS_PLUGIN_ERROR_FAILED,
"SQL error: %s", error_msg);
sqlite3_free (error_msg);
- ret = FALSE;
- goto out;
+ return FALSE;
}
/* success */
@@ -651,9 +600,7 @@ gs_plugin_resolve_app (GsPlugin *plugin,
*rating = helper.rating;
if (confidence != NULL)
*confidence = helper.confidence;
-out:
- g_free (statement);
- return ret;
+ return TRUE;
}
/**
@@ -670,21 +617,21 @@ gs_plugin_refine (GsPlugin *plugin,
GPtrArray *sources;
GsApp *app;
const gchar *pkgname;
- gboolean ret = TRUE;
+ gboolean ret;
gint rating;
gint confidence;
guint i;
/* nothing to do here */
if ((flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_RATING) == 0)
- goto out;
+ return TRUE;
/* already loaded */
if (g_once_init_enter (&plugin->priv->loaded)) {
ret = gs_plugin_fedora_tagger_load_db (plugin, error);
g_once_init_leave (&plugin->priv->loaded, TRUE);
if (!ret)
- goto out;
+ return FALSE;
}
/* add any missing ratings data */
@@ -701,7 +648,7 @@ gs_plugin_refine (GsPlugin *plugin,
&confidence,
error);
if (!ret)
- goto out;
+ return FALSE;
if (rating != -1) {
g_debug ("fedora-tagger setting rating on %s to %i%% [%i]",
pkgname, rating, confidence);
@@ -717,6 +664,5 @@ gs_plugin_refine (GsPlugin *plugin,
}
}
}
-out:
- return ret;
+ return TRUE;
}
diff --git a/src/plugins/gs-plugin-fedora-tagger-usage.c b/src/plugins/gs-plugin-fedora-tagger-usage.c
index 3be2284..f88635b 100644
--- a/src/plugins/gs-plugin-fedora-tagger-usage.c
+++ b/src/plugins/gs-plugin-fedora-tagger-usage.c
@@ -50,7 +50,7 @@ gs_plugin_get_name (void)
void
gs_plugin_initialize (GsPlugin *plugin)
{
- GSettings *settings;
+ _cleanup_object_unref_ GSettings *settings = NULL;
plugin->priv = GS_PLUGIN_GET_PRIVATE (GsPluginPrivate);
@@ -60,17 +60,15 @@ gs_plugin_initialize (GsPlugin *plugin)
gs_plugin_set_enabled (plugin, FALSE);
g_debug ("disabling '%s' as 'send-software-usage-stats' "
"disabled in GSettings", plugin->name);
- goto out;
+ return;
}
/* check that we are running on Fedora */
if (!gs_plugin_check_distro_id (plugin, "fedora")) {
gs_plugin_set_enabled (plugin, FALSE);
g_debug ("disabling '%s' as we're not Fedora", plugin->name);
- goto out;
+ return;
}
-out:
- g_object_unref (settings);
}
/**
@@ -101,11 +99,9 @@ gs_plugin_destroy (GsPlugin *plugin)
static gboolean
gs_plugin_setup_networking (GsPlugin *plugin, GError **error)
{
- gboolean ret = TRUE;
-
/* already set up */
if (plugin->priv->session != NULL)
- goto out;
+ return TRUE;
/* set up a session */
plugin->priv->session = soup_session_sync_new_with_options (SOUP_SESSION_USER_AGENT,
@@ -113,18 +109,16 @@ gs_plugin_setup_networking (GsPlugin *plugin, GError **error)
SOUP_SESSION_TIMEOUT, 5000,
NULL);
if (plugin->priv->session == NULL) {
- ret = FALSE;
g_set_error (error,
GS_PLUGIN_ERROR,
GS_PLUGIN_ERROR_FAILED,
"%s: failed to setup networking",
plugin->name);
- goto out;
+ return FALSE;
}
soup_session_add_feature_by_type (plugin->priv->session,
SOUP_TYPE_PROXY_RESOLVER_DEFAULT);
-out:
- return ret;
+ return TRUE;
}
/**
@@ -136,11 +130,10 @@ gs_plugin_app_set_usage_pkg (GsPlugin *plugin,
gboolean is_install,
GError **error)
{
- SoupMessage *msg = NULL;
- gchar *data = NULL;
- gchar *error_msg = NULL;
- gchar *uri = NULL;
guint status_code;
+ _cleanup_free_ gchar *data = NULL;
+ _cleanup_free_ gchar *uri = NULL;
+ _cleanup_object_unref_ SoupMessage *msg = NULL;
/* create the PUT data */
uri = g_strdup_printf ("%s/api/v1/usage/%s/",
@@ -165,12 +158,6 @@ gs_plugin_app_set_usage_pkg (GsPlugin *plugin,
} else {
g_debug ("Got response: %s", msg->response_body->data);
}
-
- g_free (error_msg);
- g_free (data);
- g_free (uri);
- if (msg != NULL)
- g_object_unref (msg);
return TRUE;
}
@@ -185,18 +172,17 @@ gs_plugin_app_set_usage_app (GsPlugin *plugin,
{
GPtrArray *sources;
const gchar *pkgname;
- gboolean ret = TRUE;
+ gboolean ret;
guint i;
/* get the package name */
sources = gs_app_get_sources (app);
if (sources->len == 0)
- goto out;
+ return TRUE;
/* ensure networking is set up */
- ret = gs_plugin_setup_networking (plugin, error);
- if (!ret)
- goto out;
+ if (!gs_plugin_setup_networking (plugin, error))
+ return FALSE;
/* tell fedora-tagger about this package */
for (i = 0; i < sources->len; i++) {
@@ -206,10 +192,9 @@ gs_plugin_app_set_usage_app (GsPlugin *plugin,
is_install,
error);
if (!ret)
- goto out;
+ return FALSE;
}
-out:
- return ret;
+ return TRUE;
}
/**
diff --git a/src/plugins/gs-plugin-hardcoded-categories.c b/src/plugins/gs-plugin-hardcoded-categories.c
index e9b4e29..b700af1 100644
--- a/src/plugins/gs-plugin-hardcoded-categories.c
+++ b/src/plugins/gs-plugin-hardcoded-categories.c
@@ -164,7 +164,7 @@ gs_plugin_add_categories (GsPlugin *plugin,
}
}
}
- if (cat)
+ if (cat != NULL)
gs_category_increment_size (cat);
}
@@ -181,7 +181,6 @@ gs_plugin_add_category_apps (GsPlugin *plugin,
GsCategory *parent;
const gchar *id;
guint i;
- GsApp *app;
if (g_strcmp0 (gs_category_get_id (category), "featured") != 0)
return TRUE;
@@ -191,6 +190,7 @@ gs_plugin_add_category_apps (GsPlugin *plugin,
for (i = 0; i < G_N_ELEMENTS (featured); i++) {
if (g_strcmp0 (id, featured[i].category) == 0) {
+ _cleanup_object_unref_ GsApp *app = NULL;
app = gs_app_new (featured[i].app);
gs_plugin_add_app (list, app);
}
diff --git a/src/plugins/gs-plugin-hardcoded-featured.c b/src/plugins/gs-plugin-hardcoded-featured.c
index 35712e7..71c55ad 100644
--- a/src/plugins/gs-plugin-hardcoded-featured.c
+++ b/src/plugins/gs-plugin-hardcoded-featured.c
@@ -41,28 +41,21 @@ gs_plugin_add_featured_app (GList **list,
const gchar *id,
GError **error)
{
- GsApp *app = NULL;
- gboolean ret = TRUE;
- gchar *background = NULL;
- gchar *stroke_color = NULL;
- gchar *text_color = NULL;
- gchar *text_shadow = NULL;
+ _cleanup_free_ gchar *background = NULL;
+ _cleanup_free_ gchar *stroke_color = NULL;
+ _cleanup_free_ gchar *text_color = NULL;
+ _cleanup_free_ gchar *text_shadow = NULL;
+ _cleanup_object_unref_ GsApp *app = NULL;
background = g_key_file_get_string (kf, id, "background", error);
- if (background == NULL) {
- ret = FALSE;
- goto out;
- }
+ if (background == NULL)
+ return FALSE;
stroke_color = g_key_file_get_string (kf, id, "stroke", error);
- if (stroke_color == NULL) {
- ret = FALSE;
- goto out;
- }
+ if (stroke_color == NULL)
+ return FALSE;
text_color = g_key_file_get_string (kf, id, "text", error);
- if (text_color == NULL) {
- ret = FALSE;
- goto out;
- }
+ if (text_color == NULL)
+ return FALSE;
/* optional */
text_shadow = g_key_file_get_string (kf, id, "text-shadow", NULL);
@@ -76,14 +69,7 @@ gs_plugin_add_featured_app (GList **list,
if (text_shadow != NULL)
gs_app_set_metadata (app, "Featured::text-shadow", text_shadow);
gs_plugin_add_app (list, app);
-out:
- if (app != NULL)
- g_object_unref (app);
- g_free (background);
- g_free (stroke_color);
- g_free (text_color);
- g_free (text_shadow);
- return ret;
+ return TRUE;
}
/**
@@ -95,27 +81,19 @@ gs_plugin_add_featured (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
- GKeyFile *kf;
- gboolean ret = TRUE;
- gchar **apps = NULL;
- gchar *path;
guint i;
+ _cleanup_free_ gchar *path = NULL;
+ _cleanup_keyfile_unref_ GKeyFile *kf = NULL;
+ _cleanup_strv_free_ gchar **apps = NULL;
path = g_build_filename (DATADIR, "gnome-software", "featured.ini", NULL);
kf = g_key_file_new ();
- ret = g_key_file_load_from_file (kf, path, 0, error);
- if (!ret)
- goto out;
+ if (!g_key_file_load_from_file (kf, path, 0, error))
+ return FALSE;
apps = g_key_file_get_groups (kf, NULL);
for (i = 0; apps[i]; i++) {
- ret = gs_plugin_add_featured_app (list, kf, apps[i], error);
- if (!ret)
- goto out;
+ if (!gs_plugin_add_featured_app (list, kf, apps[i], error))
+ return FALSE;
}
-out:
- if (kf != NULL)
- g_key_file_unref (kf);
- g_free (path);
- g_strfreev (apps);
- return ret;
+ return TRUE;
}
diff --git a/src/plugins/gs-plugin-local-ratings.c b/src/plugins/gs-plugin-local-ratings.c
index d4a96dd..bc74bd9 100644
--- a/src/plugins/gs-plugin-local-ratings.c
+++ b/src/plugins/gs-plugin-local-ratings.c
@@ -88,23 +88,20 @@ gs_plugin_local_ratings_load_db (GsPlugin *plugin,
GError **error)
{
const gchar *statement;
- gboolean ret = TRUE;
gchar *error_msg = NULL;
gint rc;
g_debug ("trying to open database '%s'", plugin->priv->db_path);
- ret = gs_mkdir_parent (plugin->priv->db_path, error);
- if (!ret)
- goto out;
+ if (!gs_mkdir_parent (plugin->priv->db_path, error))
+ return FALSE;
rc = sqlite3_open (plugin->priv->db_path, &plugin->priv->db);
if (rc != SQLITE_OK) {
- ret = FALSE;
g_set_error (error,
GS_PLUGIN_ERROR,
GS_PLUGIN_ERROR_FAILED,
"Can't open transaction database: %s",
sqlite3_errmsg (plugin->priv->db));
- goto out;
+ return FALSE;
}
/* we don't need to keep doing fsync */
@@ -120,10 +117,7 @@ gs_plugin_local_ratings_load_db (GsPlugin *plugin,
"rating INTEGER DEFAULT 0);";
sqlite3_exec (plugin->priv->db, statement, NULL, NULL, NULL);
}
-
- /* success */
-out:
- return ret;
+ return TRUE;
}
/**
@@ -143,8 +137,8 @@ gs_plugin_local_ratings_sqlite_cb (void *data, gint argc, gchar **argv, gchar **
static gint
gs_plugin_local_find_app (GsPlugin *plugin, const gchar *app_id)
{
- gchar *statement;
gint rating = -1;
+ _cleanup_free_ gchar *statement = NULL;
statement = g_strdup_printf ("SELECT rating FROM ratings WHERE app_id = '%s'", app_id);
sqlite3_exec (plugin->priv->db,
@@ -152,7 +146,6 @@ gs_plugin_local_find_app (GsPlugin *plugin, const gchar *app_id)
gs_plugin_local_ratings_sqlite_cb,
&rating,
NULL);
- g_free (statement);
return rating;
}
@@ -165,10 +158,10 @@ gs_plugin_app_set_rating (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
- gboolean ret = TRUE;
- gchar *error_msg = NULL;
- gchar *statement = NULL;
+ char *error_msg = NULL;
+ gboolean ret;
gint rc;
+ _cleanup_free_ gchar *statement = NULL;
/* already loaded */
if (g_once_init_enter (&plugin->priv->loaded)) {
@@ -176,7 +169,7 @@ gs_plugin_app_set_rating (GsPlugin *plugin,
g_once_init_leave (&plugin->priv->loaded, TRUE);
if (!ret)
- goto out;
+ return FALSE;
}
/* insert the entry */
@@ -191,12 +184,9 @@ gs_plugin_app_set_rating (GsPlugin *plugin,
GS_PLUGIN_ERROR_FAILED,
"SQL error: %s", error_msg);
sqlite3_free (error_msg);
- ret = FALSE;
- goto out;
+ return FALSE;
}
-out:
- g_free (statement);
- return ret;
+ return TRUE;
}
@@ -210,22 +200,21 @@ gs_plugin_refine (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
- gboolean ret = TRUE;
+ gboolean ret;
gint rating;
GList *l;
GsApp *app;
/* nothing to do here */
if ((flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_RATING) == 0)
- goto out;
+ return TRUE;
/* already loaded */
if (g_once_init_enter (&plugin->priv->loaded)) {
ret = gs_plugin_local_ratings_load_db (plugin, error);
g_once_init_leave (&plugin->priv->loaded, TRUE);
-
if (!ret)
- goto out;
+ return FALSE;
}
/* add any missing ratings data */
@@ -244,6 +233,5 @@ gs_plugin_refine (GsPlugin *plugin,
gs_app_add_kudo (app, GS_APP_KUDO_POPULAR);
}
}
-out:
- return ret;
+ return TRUE;
}
diff --git a/src/plugins/gs-plugin-menu-spec-categories.c b/src/plugins/gs-plugin-menu-spec-categories.c
index 8cfce35..e0f47d5 100644
--- a/src/plugins/gs-plugin-menu-spec-categories.c
+++ b/src/plugins/gs-plugin-menu-spec-categories.c
@@ -45,7 +45,6 @@ gs_plugin_add_categories (GsPlugin *plugin,
GError **error)
{
GsCategory *category = NULL;
- GsCategory *sub;
const MenuSpecData *msdata;
gchar *tmp;
gchar msgctxt[100];
@@ -61,11 +60,11 @@ gs_plugin_add_categories (GsPlugin *plugin,
*list = g_list_prepend (*list, category);
g_snprintf(msgctxt, 100, "Menu subcategory of %s", msdata[i].text);
} else {
+ _cleanup_object_unref_ GsCategory *sub = NULL;
sub = gs_category_new (category,
tmp + 2,
g_dpgettext2(GETTEXT_PACKAGE, msgctxt, msdata[i].text));
gs_category_add_subcategory (category, sub);
- g_object_unref (sub);
}
}
diff --git a/src/plugins/gs-plugin-menu-spec-refine.c b/src/plugins/gs-plugin-menu-spec-refine.c
index 99cc83b..bfbce0f 100644
--- a/src/plugins/gs-plugin-menu-spec-refine.c
+++ b/src/plugins/gs-plugin-menu-spec-refine.c
@@ -71,11 +71,11 @@ gs_plugin_refine_app_category (GsPlugin *plugin,
continue;
ret = gs_app_has_category (app, tmp + 2);
if (ret) {
- tmp = g_strdup_printf ("%s → %s",
+ _cleanup_free_ gchar *str = NULL;
+ str = g_strdup_printf ("%s → %s",
gettext (cat->text),
gettext (msdata[i].text));
- gs_app_set_menu_path (app, tmp);
- g_free (tmp);
+ gs_app_set_menu_path (app, str);
break;
}
}
@@ -121,22 +121,19 @@ gs_plugin_refine (GsPlugin *plugin,
{
GList *l;
GsApp *app;
- gboolean ret;
/* nothing to do here */
if ((flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_MENU_PATH) == 0)
- goto out;
+ return TRUE;
for (l = *list; l != NULL; l = l->next) {
app = GS_APP (l->data);
if (gs_app_get_menu_path (app) == NULL) {
- ret = gs_plugin_refine_app (plugin, app);
- if (!ret) {
+ if (!gs_plugin_refine_app (plugin, app)) {
/* don't keep searching for this */
gs_app_set_menu_path (app, "");
}
}
}
-out:
return TRUE;
}
diff --git a/src/plugins/gs-plugin-moduleset.c b/src/plugins/gs-plugin-moduleset.c
index 014518c..4329d95 100644
--- a/src/plugins/gs-plugin-moduleset.c
+++ b/src/plugins/gs-plugin-moduleset.c
@@ -106,17 +106,16 @@ gs_plugin_add_popular (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
- GsApp *app;
gboolean ret = TRUE;
- gchar **apps = NULL;
guint i;
+ _cleanup_strv_free_ gchar **apps = NULL;
/* load XML files */
if (g_once_init_enter (&plugin->priv->done_init)) {
ret = gs_plugin_startup (plugin, error);
g_once_init_leave (&plugin->priv->done_init, TRUE);
if (!ret)
- goto out;
+ return FALSE;
}
if (g_getenv ("GNOME_SOFTWARE_POPULAR")) {
@@ -128,24 +127,21 @@ gs_plugin_add_popular (GsPlugin *plugin,
category);
}
if (apps == NULL) {
- ret = FALSE;
g_set_error (error,
GS_PLUGIN_ERROR,
GS_PLUGIN_ERROR_FAILED,
"No moduleset data found");
- goto out;
+ return FALSE;
}
/* just add all */
for (i = 0; apps[i]; i++) {
+ _cleanup_object_unref_ GsApp *app = NULL;
app = gs_app_new (apps[i]);
gs_plugin_add_app (list, app);
gs_app_add_kudo (app, GS_APP_KUDO_FEATURED_RECOMMENDED);
- g_object_unref (app);
}
-out:
- g_strfreev (apps);
- return ret;
+ return TRUE;
}
/**
@@ -161,16 +157,16 @@ gs_plugin_refine (GsPlugin *plugin,
GList *l;
GsApp *app;
gboolean ret = TRUE;
- gchar **apps = NULL;
- gchar **pkgs = NULL;
guint i;
+ _cleanup_strv_free_ gchar **apps = NULL;
+ _cleanup_strv_free_ gchar **pkgs = NULL;
/* load XML files */
if (g_once_init_enter (&plugin->priv->done_init)) {
ret = gs_plugin_startup (plugin, error);
g_once_init_leave (&plugin->priv->done_init, TRUE);
if (!ret)
- goto out;
+ return FALSE;
}
/* just mark each one as core */
@@ -188,12 +184,11 @@ gs_plugin_refine (GsPlugin *plugin,
}
}
if (apps == NULL) {
- ret = FALSE;
g_set_error (error,
GS_PLUGIN_ERROR,
GS_PLUGIN_ERROR_FAILED,
"No moduleset data found");
- goto out;
+ return FALSE;
}
/* just mark each one as core */
@@ -210,10 +205,7 @@ gs_plugin_refine (GsPlugin *plugin,
}
}
}
-out:
- g_strfreev (apps);
- g_strfreev (pkgs);
- return ret;
+ return TRUE;
}
/* vim: set noexpandtab: */
diff --git a/src/plugins/gs-plugin-packagekit-history.c b/src/plugins/gs-plugin-packagekit-history.c
index 6de6c7a..d70df2a 100644
--- a/src/plugins/gs-plugin-packagekit-history.c
+++ b/src/plugins/gs-plugin-packagekit-history.c
@@ -82,9 +82,9 @@ gs_plugin_packagekit_refine_add_history (GsApp *app, GVariant *dict)
{
const gchar *version;
gboolean ret;
- GsApp *history;
guint64 timestamp;
PkInfoEnum info_enum;
+ _cleanup_object_unref_ GsApp *history = NULL;
/* create new history item with same ID as parent */
history = gs_app_new (gs_app_get_id (app));
@@ -105,15 +105,9 @@ gs_plugin_packagekit_refine_add_history (GsApp *app, GVariant *dict)
gs_app_set_state (history, AS_APP_STATE_UPDATABLE);
break;
default:
- ret = FALSE;
- break;
- }
-
- /* we have nothing useful to show for this item */
- if (!ret) {
g_debug ("ignoring history kind: %s",
pk_info_enum_to_string (info_enum));
- goto out;
+ return;
}
/* set the history time and date */
@@ -131,8 +125,6 @@ gs_plugin_packagekit_refine_add_history (GsApp *app, GVariant *dict)
/* use the last event as approximation of the package timestamp */
gs_app_set_install_date (app, timestamp);
-out:
- g_object_unref (history);
}
/**
@@ -141,13 +133,10 @@ out:
static gboolean
gs_plugin_load (GsPlugin *plugin, GCancellable *cancellable, GError **error)
{
- gboolean ret = TRUE;
plugin->priv->connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM,
cancellable,
error);
- if (plugin->priv->connection == NULL)
- ret = FALSE;
- return ret;
+ return plugin->priv->connection != NULL;
}
static gboolean
@@ -156,24 +145,23 @@ gs_plugin_packagekit_refine (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
- const gchar **package_names = NULL;
- gboolean ret = TRUE;
+ gboolean ret;
GError *error_local = NULL;
GList *l;
GsApp *app;
- GsApp *app_dummy;
guint i = 0;
GVariantIter iter;
- GVariant *result = NULL;
- GVariant *tuple = NULL;
GVariant *value;
+ _cleanup_free_ const gchar **package_names = NULL;
+ _cleanup_variant_unref_ GVariant *result = NULL;
+ _cleanup_variant_unref_ GVariant *tuple = NULL;
/* already loaded */
if (g_once_init_enter (&plugin->priv->loaded)) {
ret = gs_plugin_load (plugin, cancellable, error);
g_once_init_leave (&plugin->priv->loaded, TRUE);
if (!ret)
- goto out;
+ return FALSE;
}
/* get an array of package names */
@@ -219,11 +207,9 @@ gs_plugin_packagekit_refine (GsPlugin *plugin,
app = GS_APP (l->data);
gs_app_set_install_date (app, GS_APP_INSTALL_DATE_UNKNOWN);
}
- } else {
- ret = FALSE;
- g_propagate_error (error, error_local);
}
- goto out;
+ g_propagate_error (error, error_local);
+ return FALSE;
}
/* get any results */
@@ -238,13 +224,13 @@ gs_plugin_packagekit_refine (GsPlugin *plugin,
/* make up a fake entry as we know this package was at
* least installed at some point in time */
if (gs_app_get_state (app) == AS_APP_STATE_INSTALLED) {
+ _cleanup_object_unref_ GsApp *app_dummy = NULL;
app_dummy = gs_app_new (gs_app_get_id (app));
gs_app_set_install_date (app_dummy, GS_APP_INSTALL_DATE_UNKNOWN);
gs_app_set_kind (app_dummy, GS_APP_KIND_PACKAGE);
gs_app_set_state (app_dummy, AS_APP_STATE_INSTALLED);
gs_app_set_version (app_dummy, gs_app_get_version (app));
gs_app_add_history (app, app_dummy);
- g_object_unref (app_dummy);
}
gs_app_set_install_date (app, GS_APP_INSTALL_DATE_UNKNOWN);
continue;
@@ -257,16 +243,7 @@ gs_plugin_packagekit_refine (GsPlugin *plugin,
g_variant_unref (value);
}
}
-
- /* success */
- ret = TRUE;
-out:
- g_free (package_names);
- if (tuple != NULL)
- g_variant_unref (tuple);
- if (result != NULL)
- g_variant_unref (result);
- return ret;
+ return TRUE;
}
/**
@@ -279,14 +256,14 @@ gs_plugin_refine (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
- gboolean ret = TRUE;
+ gboolean ret;
GList *l;
- GList *packages = NULL;
GsApp *app;
GPtrArray *sources;
+ _cleanup_list_free_ GList *packages = NULL;
if ((flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_HISTORY) == 0)
- goto out;
+ return TRUE;
/* add any missing history data */
for (l = *list; l != NULL; l = l->next) {
@@ -304,9 +281,7 @@ gs_plugin_refine (GsPlugin *plugin,
cancellable,
error);
if (!ret)
- goto out;
+ return FALSE;
}
-out:
- g_list_free (packages);
- return ret;
+ return TRUE;
}
diff --git a/src/plugins/gs-plugin-packagekit-offline.c b/src/plugins/gs-plugin-packagekit-offline.c
index 20eb00a..76ac944 100644
--- a/src/plugins/gs-plugin-packagekit-offline.c
+++ b/src/plugins/gs-plugin-packagekit-offline.c
@@ -44,18 +44,16 @@ gs_plugin_add_updates_historical (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
- gboolean ret = TRUE;
- gchar **package_ids = NULL;
- gchar *error_details = NULL;
- gchar *packages = NULL;
- gchar **split;
- GKeyFile *key_file = NULL;
- GsApp *app;
+ gboolean ret;
guint i;
+ _cleanup_strv_free_ gchar **package_ids = NULL;
+ _cleanup_free_ gchar *error_details = NULL;
+ _cleanup_free_ gchar *packages = NULL;
+ _cleanup_keyfile_unref_ GKeyFile *key_file = NULL;
/* was any offline update attempted */
if (!g_file_test (PK_OFFLINE_UPDATE_RESULTS_FILENAME, G_FILE_TEST_EXISTS))
- goto out;
+ return TRUE;
/* open the file */
key_file = g_key_file_new ();
@@ -64,7 +62,7 @@ gs_plugin_add_updates_historical (GsPlugin *plugin,
G_KEY_FILE_NONE,
error);
if (!ret)
- goto out;
+ return FALSE;
/* only return results if successful */
ret = g_key_file_get_boolean (key_file,
@@ -77,12 +75,12 @@ gs_plugin_add_updates_historical (GsPlugin *plugin,
"ErrorDetails",
error);
if (error_details == NULL)
- goto out;
+ return FALSE;
g_set_error_literal (error,
GS_PLUGIN_ERROR,
GS_PLUGIN_ERROR_FAILED,
error_details);
- goto out;
+ return FALSE;
}
/* get list of package-ids */
@@ -91,16 +89,17 @@ gs_plugin_add_updates_historical (GsPlugin *plugin,
"Packages",
NULL);
if (packages == NULL) {
- ret = FALSE;
g_set_error (error,
GS_PLUGIN_ERROR,
GS_PLUGIN_ERROR_NOT_SUPPORTED,
"No 'Packages' in %s",
PK_OFFLINE_UPDATE_RESULTS_FILENAME);
- goto out;
+ return FALSE;
}
package_ids = g_strsplit (packages, ",", -1);
for (i = 0; package_ids[i] != NULL; i++) {
+ _cleanup_object_unref_ GsApp *app = NULL;
+ _cleanup_strv_free_ gchar **split = NULL;
app = gs_app_new (NULL);
split = g_strsplit (package_ids[i], ";", 4);
gs_app_add_source (app, split[0]);
@@ -110,13 +109,6 @@ gs_plugin_add_updates_historical (GsPlugin *plugin,
gs_app_set_state (app, AS_APP_STATE_UPDATABLE);
gs_app_set_kind (app, GS_APP_KIND_PACKAGE);
gs_plugin_add_app (list, app);
- g_strfreev (split);
}
-out:
- g_free (error_details);
- g_free (packages);
- g_strfreev (package_ids);
- if (key_file != NULL)
- g_key_file_free (key_file);
- return ret;
+ return TRUE;
}
diff --git a/src/plugins/gs-plugin-packagekit-refine.c b/src/plugins/gs-plugin-packagekit-refine.c
index e9db9f7..ad9bdd5 100644
--- a/src/plugins/gs-plugin-packagekit-refine.c
+++ b/src/plugins/gs-plugin-packagekit-refine.c
@@ -160,7 +160,6 @@ gs_plugin_packagekit_resolve_packages_app (GsPlugin *plugin,
PkPackage *package;
const gchar *data;
const gchar *pkgname;
- gchar *tmp;
guint i, j;
guint number_available = 0;
guint number_installed = 0;
@@ -232,10 +231,10 @@ gs_plugin_packagekit_resolve_packages_app (GsPlugin *plugin,
gs_app_set_state (app, AS_APP_STATE_UNKNOWN);
gs_app_set_state (app, AS_APP_STATE_UPDATABLE);
} else if (number_installed + number_available < sources->len) {
+ _cleanup_free_ gchar *tmp = NULL;
/* we have less packages returned than source packages */
tmp = gs_app_to_string (app);
g_debug ("Failed to find all packages for:\n%s", tmp);
- g_free (tmp);
gs_app_set_kind (app, GS_APP_KIND_UNKNOWN);
gs_app_set_state (app, AS_APP_STATE_UNAVAILABLE);
}
@@ -251,16 +250,15 @@ gs_plugin_packagekit_resolve_packages (GsPlugin *plugin,
GError **error)
{
GList *l;
- GPtrArray *array = NULL;
- GPtrArray *package_ids = NULL;
- GPtrArray *packages = NULL;
GPtrArray *sources;
GsApp *app;
- PkError *error_code = NULL;
- PkResults *results = NULL;
const gchar *pkgname;
- gboolean ret = TRUE;
guint i;
+ _cleanup_object_unref_ PkError *error_code = NULL;
+ _cleanup_object_unref_ PkResults *results = NULL;
+ _cleanup_ptrarray_unref_ GPtrArray *array = NULL;
+ _cleanup_ptrarray_unref_ GPtrArray *package_ids = NULL;
+ _cleanup_ptrarray_unref_ GPtrArray *packages = NULL;
package_ids = g_ptr_array_new_with_free_func (g_free);
for (l = list; l != NULL; l = l->next) {
@@ -280,22 +278,19 @@ gs_plugin_packagekit_resolve_packages (GsPlugin *plugin,
cancellable,
gs_plugin_packagekit_progress_cb, plugin,
error);
- if (results == NULL) {
- ret = FALSE;
- goto out;
- }
+ if (results == NULL)
+ return FALSE;
/* check error code */
error_code = pk_results_get_error_code (results);
if (error_code != NULL) {
- ret = FALSE;
g_set_error (error,
GS_PLUGIN_ERROR,
GS_PLUGIN_ERROR_FAILED,
"failed to resolve: %s, %s",
pk_error_enum_to_string (pk_error_get_code (error_code)),
pk_error_get_details (error_code));
- goto out;
+ return FALSE;
}
/* get results */
@@ -304,18 +299,7 @@ gs_plugin_packagekit_resolve_packages (GsPlugin *plugin,
app = GS_APP (l->data);
gs_plugin_packagekit_resolve_packages_app (plugin, packages, app);
}
-out:
- if (package_ids != NULL)
- g_ptr_array_unref (package_ids);
- if (packages != NULL)
- g_ptr_array_unref (packages);
- if (error_code != NULL)
- g_object_unref (error_code);
- if (array != NULL)
- g_ptr_array_unref (array);
- if (results != NULL)
- g_object_unref (results);
- return ret;
+ return TRUE;
}
static gboolean
@@ -326,12 +310,10 @@ gs_plugin_packagekit_refine_from_desktop (GsPlugin *plugin,
GError **error)
{
const gchar *to_array[] = { NULL, NULL };
- gboolean ret = TRUE;
- GPtrArray *array = NULL;
- GPtrArray *packages = NULL;
- PkError *error_code = NULL;
- PkPackage *package;
- PkResults *results = NULL;
+ _cleanup_object_unref_ PkError *error_code = NULL;
+ _cleanup_object_unref_ PkResults *results = NULL;
+ _cleanup_ptrarray_unref_ GPtrArray *array = NULL;
+ _cleanup_ptrarray_unref_ GPtrArray *packages = NULL;
to_array[0] = filename;
results = pk_client_search_files (plugin->priv->client,
@@ -340,27 +322,25 @@ gs_plugin_packagekit_refine_from_desktop (GsPlugin *plugin,
cancellable,
gs_plugin_packagekit_progress_cb, plugin,
error);
- if (results == NULL) {
- ret = FALSE;
- goto out;
- }
+ if (results == NULL)
+ return FALSE;
/* check error code */
error_code = pk_results_get_error_code (results);
if (error_code != NULL) {
- ret = FALSE;
g_set_error (error,
GS_PLUGIN_ERROR,
GS_PLUGIN_ERROR_FAILED,
"failed to search files: %s, %s",
pk_error_enum_to_string (pk_error_get_code (error_code)),
pk_error_get_details (error_code));
- goto out;
+ return FALSE;
}
/* get results */
packages = pk_results_get_package_array (results);
if (packages->len == 1) {
+ PkPackage *package;
package = g_ptr_array_index (packages, 0);
gs_app_add_source_id (app, pk_package_get_id (package));
gs_app_set_state (app, AS_APP_STATE_INSTALLED);
@@ -369,16 +349,7 @@ gs_plugin_packagekit_refine_from_desktop (GsPlugin *plugin,
g_warning ("Failed to find one package for %s, %s, [%d]",
gs_app_get_id (app), filename, packages->len);
}
-out:
- if (packages != NULL)
- g_ptr_array_unref (packages);
- if (error_code != NULL)
- g_object_unref (error_code);
- if (array != NULL)
- g_ptr_array_unref (array);
- if (results != NULL)
- g_object_unref (results);
- return ret;
+ return TRUE;
}
/**
@@ -391,15 +362,14 @@ gs_plugin_packagekit_refine_updatedetails (GsPlugin *plugin,
GError **error)
{
const gchar *package_id;
- gboolean ret = TRUE;
- const gchar **package_ids;
GList *l;
- GPtrArray *array = NULL;
GsApp *app;
guint i = 0;
guint size;
- PkResults *results = NULL;
PkUpdateDetail *update_detail;
+ _cleanup_free_ const gchar **package_ids = NULL;
+ _cleanup_object_unref_ PkResults *results = NULL;
+ _cleanup_ptrarray_unref_ GPtrArray *array = NULL;
size = g_list_length (list);
package_ids = g_new0 (const gchar *, size + 1);
@@ -415,10 +385,8 @@ gs_plugin_packagekit_refine_updatedetails (GsPlugin *plugin,
cancellable,
gs_plugin_packagekit_progress_cb, plugin,
error);
- if (results == NULL) {
- ret = FALSE;
- goto out;
- }
+ if (results == NULL)
+ return FALSE;
/* set the update details for the update */
array = pk_results_get_update_detail_array (results);
@@ -434,13 +402,7 @@ gs_plugin_packagekit_refine_updatedetails (GsPlugin *plugin,
break;
}
}
-out:
- if (array != NULL)
- g_ptr_array_unref (array);
- if (results != NULL)
- g_object_unref (results);
- g_free (package_ids);
- return ret;
+ return TRUE;
}
/**
@@ -464,9 +426,9 @@ gs_pk_format_desc (const gchar *text)
static gboolean
gs_pk_compare_ids (const gchar *package_id1, const gchar *package_id2)
{
- gchar **split1;
- gchar **split2;
gboolean ret;
+ _cleanup_strv_free_ gchar **split1 = NULL;
+ _cleanup_strv_free_ gchar **split2 = NULL;
split1 = pk_package_id_split (package_id1);
split2 = pk_package_id_split (package_id2);
@@ -476,8 +438,6 @@ gs_pk_compare_ids (const gchar *package_id1, const gchar *package_id2)
split2[PK_PACKAGE_ID_VERSION]) == 0 &&
g_strcmp0 (split1[PK_PACKAGE_ID_ARCH],
split2[PK_PACKAGE_ID_ARCH]) == 0);
- g_strfreev (split1);
- g_strfreev (split2);
return ret;
}
@@ -492,7 +452,6 @@ gs_plugin_packagekit_refine_details_app (GsPlugin *plugin,
GPtrArray *source_ids;
PkDetails *details;
const gchar *package_id;
- gchar *desc;
guint i;
guint j;
guint64 size = 0;
@@ -501,6 +460,7 @@ gs_plugin_packagekit_refine_details_app (GsPlugin *plugin,
for (j = 0; j < source_ids->len; j++) {
package_id = g_ptr_array_index (source_ids, j);
for (i = 0; i < array->len; i++) {
+ _cleanup_free_ gchar *desc = NULL;
/* right package? */
details = g_ptr_array_index (array, i);
if (!gs_pk_compare_ids (package_id,
@@ -524,7 +484,6 @@ gs_plugin_packagekit_refine_details_app (GsPlugin *plugin,
GS_APP_QUALITY_LOWEST,
pk_details_get_summary (details));
#endif
- g_free (desc);
break;
}
}
@@ -544,14 +503,13 @@ gs_plugin_packagekit_refine_details (GsPlugin *plugin,
GError **error)
{
GList *l;
- GPtrArray *array = NULL;
- GPtrArray *package_ids;
GPtrArray *source_ids;
GsApp *app;
- PkResults *results = NULL;
const gchar *package_id;
- gboolean ret = TRUE;
guint i;
+ _cleanup_ptrarray_unref_ GPtrArray *array = NULL;
+ _cleanup_ptrarray_unref_ GPtrArray *package_ids = NULL;
+ _cleanup_object_unref_ PkResults *results = NULL;
package_ids = g_ptr_array_new_with_free_func (g_free);
for (l = list; l != NULL; l = l->next) {
@@ -570,10 +528,8 @@ gs_plugin_packagekit_refine_details (GsPlugin *plugin,
cancellable,
gs_plugin_packagekit_progress_cb, plugin,
error);
- if (results == NULL) {
- ret = FALSE;
- goto out;
- }
+ if (results == NULL)
+ return FALSE;
/* set the update details for the update */
array = pk_results_get_details_array (results);
@@ -581,13 +537,7 @@ gs_plugin_packagekit_refine_details (GsPlugin *plugin,
app = GS_APP (l->data);
gs_plugin_packagekit_refine_details_app (plugin, array, app);
}
-out:
- if (array != NULL)
- g_ptr_array_unref (array);
- if (results != NULL)
- g_object_unref (results);
- g_ptr_array_unref (package_ids);
- return ret;
+ return TRUE;
}
/**
@@ -617,9 +567,9 @@ gs_plugin_refine_require_details (GsPlugin *plugin,
GError **error)
{
GList *l;
- GList *list_tmp = NULL;
GsApp *app;
gboolean ret = TRUE;
+ _cleanup_list_free_ GList *list_tmp = NULL;
gs_profile_start (plugin->profile, "packagekit-refine[source->licence]");
for (l = list; l != NULL; l = l->next) {
@@ -642,7 +592,6 @@ gs_plugin_refine_require_details (GsPlugin *plugin,
goto out;
out:
gs_profile_stop (plugin->profile, "packagekit-refine[source->licence]");
- g_list_free (list_tmp);
return ret;
}
@@ -654,11 +603,10 @@ gs_plugin_packagekit_get_source_list (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
- GPtrArray *array = NULL;
PkRepoDetail *rd;
- PkResults *results;
- gboolean ret = TRUE;
guint i;
+ _cleanup_object_unref_ PkResults *results = NULL;
+ _cleanup_ptrarray_unref_ GPtrArray *array = NULL;
/* ask PK for the repo details */
results = pk_client_get_repo_list (plugin->priv->client,
@@ -666,10 +614,8 @@ gs_plugin_packagekit_get_source_list (GsPlugin *plugin,
cancellable,
gs_plugin_packagekit_progress_cb, plugin,
error);
- if (results == NULL) {
- ret = FALSE;
- goto out;
- }
+ if (results == NULL)
+ return FALSE;
array = pk_results_get_repo_detail_array (results);
for (i = 0; i < array->len; i++) {
rd = g_ptr_array_index (array, i);
@@ -679,12 +625,7 @@ gs_plugin_packagekit_get_source_list (GsPlugin *plugin,
g_strdup (pk_repo_detail_get_description (rd)));
#endif
}
-out:
- if (array != NULL)
- g_ptr_array_unref (array);
- if (results != NULL)
- g_object_unref (results);
- return ret;
+ return TRUE;
}
/**
@@ -753,13 +694,13 @@ gs_plugin_refine (GsPlugin *plugin,
GError **error)
{
GList *l;
- GList *resolve_all = NULL;
- GList *updatedetails_all = NULL;
GPtrArray *sources;
GsApp *app;
const gchar *profile_id = NULL;
const gchar *tmp;
gboolean ret = TRUE;
+ _cleanup_list_free_ GList *resolve_all = NULL;
+ _cleanup_list_free_ GList *updatedetails_all = NULL;
/* get the repo_id -> repo_name mapping set up */
if ((flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_ORIGIN) > 0 &&
@@ -857,7 +798,5 @@ gs_plugin_refine (GsPlugin *plugin,
out:
if (profile_id != NULL)
gs_profile_stop (plugin->profile, profile_id);
- g_list_free (resolve_all);
- g_list_free (updatedetails_all);
return ret;
}
diff --git a/src/plugins/gs-plugin-packagekit-refresh.c b/src/plugins/gs-plugin-packagekit-refresh.c
index 0a71eed..9bfd454 100644
--- a/src/plugins/gs-plugin-packagekit-refresh.c
+++ b/src/plugins/gs-plugin-packagekit-refresh.c
@@ -106,17 +106,16 @@ gs_plugin_refresh (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
- gboolean ret = TRUE;
- gchar **package_ids = NULL;
PkBitfield filter;
PkBitfield transaction_flags;
- PkPackageSack *sack = NULL;
- PkResults *results2 = NULL;
- PkResults *results = NULL;
+ _cleanup_strv_free_ gchar **package_ids = NULL;
+ _cleanup_object_unref_ PkPackageSack *sack = NULL;
+ _cleanup_object_unref_ PkResults *results2 = NULL;
+ _cleanup_object_unref_ PkResults *results = NULL;
/* not us */
if ((flags & GS_PLUGIN_REFRESH_FLAGS_UPDATES) == 0)
- goto out;
+ return TRUE;
/* update UI as this might take some time */
gs_plugin_status_update (plugin, NULL, GS_PLUGIN_STATUS_WAITING);
@@ -129,15 +128,13 @@ gs_plugin_refresh (GsPlugin *plugin,
cancellable,
gs_plugin_packagekit_progress_cb, plugin,
error);
- if (results == NULL) {
- ret = FALSE;
- goto out;
- }
+ if (results == NULL)
+ return FALSE;
/* download all the updates */
sack = pk_results_get_package_sack (results);
if (pk_package_sack_get_size (sack) == 0)
- goto out;
+ return TRUE;
package_ids = pk_package_sack_get_ids (sack);
transaction_flags = pk_bitfield_value (PK_TRANSACTION_FLAG_ENUM_ONLY_DOWNLOAD);
results2 = pk_client_update_packages (PK_CLIENT (plugin->priv->task),
@@ -146,19 +143,7 @@ gs_plugin_refresh (GsPlugin *plugin,
cancellable,
gs_plugin_packagekit_progress_cb, plugin,
error);
- if (results2 == NULL) {
- ret = FALSE;
- goto out;
- }
-out:
- g_strfreev (package_ids);
- if (sack != NULL)
- g_object_unref (sack);
- if (results2 != NULL)
- g_object_unref (results2);
- if (results != NULL)
- g_object_unref (results);
- return ret;
+ return results2 != NULL;
}
/**
@@ -173,7 +158,7 @@ static void
gs_plugin_packagekit_refresh_set_text (GsApp *app, const gchar *text)
{
gchar *nl;
- gchar *tmp;
+ _cleanup_free_ gchar *tmp = NULL;
/* look for newline */
tmp = g_strdup (text);
@@ -181,16 +166,14 @@ gs_plugin_packagekit_refresh_set_text (GsApp *app, const gchar *text)
if (nl == NULL) {
if (strlen (text) < 40) {
gs_app_set_summary (app, GS_APP_QUALITY_LOWEST, text);
- goto out;
+ return;
}
gs_app_set_description (app, GS_APP_QUALITY_LOWEST, text);
- goto out;
+ return;
}
*nl = '\0';
gs_app_set_summary (app, GS_APP_QUALITY_LOWEST, tmp);
gs_app_set_description (app, GS_APP_QUALITY_LOWEST, nl + 1);
-out:
- g_free (tmp);
}
/**
@@ -204,14 +187,13 @@ gs_plugin_filename_to_app (GsPlugin *plugin,
GError **error)
{
const gchar *package_id;
- gboolean ret = TRUE;
- gchar *basename = NULL;
- gchar **files;
- gchar **split = NULL;
- GPtrArray *array = NULL;
- GsApp *app = NULL;
PkDetails *item;
PkResults *results = NULL;
+ _cleanup_free_ gchar *basename = NULL;
+ _cleanup_strv_free_ gchar **files = NULL;
+ _cleanup_strv_free_ gchar **split = NULL;
+ _cleanup_ptrarray_unref_ GPtrArray *array = NULL;
+ _cleanup_object_unref_ GsApp *app = NULL;
/* get details */
files = g_strsplit (filename, "\t", -1);
@@ -228,29 +210,25 @@ gs_plugin_filename_to_app (GsPlugin *plugin,
GS_PLUGIN_ERROR_FAILED,
"GetDetailsLocal() not supported");
#endif
- if (results == NULL) {
- ret = FALSE;
- goto out;
- }
+ if (results == NULL)
+ return FALSE;
/* get results */
array = pk_results_get_details_array (results);
if (array->len == 0) {
- ret = FALSE;
g_set_error (error,
GS_PLUGIN_ERROR,
GS_PLUGIN_ERROR_FAILED,
"no details for %s", filename);
- goto out;
+ return FALSE;
}
if (array->len > 1) {
- ret = FALSE;
g_set_error (error,
GS_PLUGIN_ERROR,
GS_PLUGIN_ERROR_FAILED,
"too many details [%i] for %s",
array->len, filename);
- goto out;
+ return FALSE;
}
/* create application */
@@ -280,14 +258,5 @@ gs_plugin_filename_to_app (GsPlugin *plugin,
gs_app_set_size (app, pk_details_get_size (item));
gs_app_set_licence (app, pk_details_get_license (item));
gs_plugin_add_app (list, app);
-out:
- if (app != NULL)
- g_object_unref (app);
- if (array != NULL)
- g_ptr_array_unref (array);
- if (basename != NULL)
- g_free (basename);
- g_strfreev (split);
- g_strfreev (files);
- return ret;
+ return TRUE;
}
diff --git a/src/plugins/gs-plugin-packagekit.c b/src/plugins/gs-plugin-packagekit.c
index 56e105c..5df18df 100644
--- a/src/plugins/gs-plugin-packagekit.c
+++ b/src/plugins/gs-plugin-packagekit.c
@@ -106,9 +106,8 @@ gs_plugin_add_installed (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
- gboolean ret = TRUE;
PkBitfield filter;
- PkResults *results;
+ _cleanup_object_unref_ PkResults *results = NULL;
/* update UI as this might take some time */
gs_plugin_status_update (plugin, NULL, GS_PLUGIN_STATUS_WAITING);
@@ -125,19 +124,11 @@ gs_plugin_add_installed (GsPlugin *plugin,
cancellable,
gs_plugin_packagekit_progress_cb, plugin,
error);
- if (results == NULL) {
- ret = FALSE;
- goto out;
- }
+ if (results == NULL)
+ return FALSE;
/* add results */
- ret = gs_plugin_packagekit_add_results (plugin, list, results, error);
- if (!ret)
- goto out;
-out:
- if (results != NULL)
- g_object_unref (results);
- return ret;
+ return gs_plugin_packagekit_add_results (plugin, list, results, error);
}
/**
@@ -154,10 +145,9 @@ gs_plugin_add_sources_related (GsPlugin *plugin,
GsApp *app;
GsApp *app_tmp;
PkBitfield filter;
- PkResults *results = NULL;
const gchar *id;
gboolean ret = TRUE;
- gchar **split;
+ _cleanup_object_unref_ PkResults *results = NULL;
gs_profile_start (plugin->profile, "packagekit::add-sources-related");
filter = pk_bitfield_from_enums (PK_FILTER_ENUM_INSTALLED,
@@ -181,6 +171,7 @@ gs_plugin_add_sources_related (GsPlugin *plugin,
if (!ret)
goto out;
for (l = installed; l != NULL; l = l->next) {
+ _cleanup_strv_free_ gchar **split = NULL;
app = GS_APP (l->data);
split = pk_package_id_split (gs_app_get_source_id_default (app));
if (g_str_has_prefix (split[PK_PACKAGE_ID_DATA], "installed:")) {
@@ -192,13 +183,10 @@ gs_plugin_add_sources_related (GsPlugin *plugin,
gs_app_add_related (app_tmp, app);
}
}
- g_strfreev (split);
}
out:
gs_profile_stop (plugin->profile, "packagekit::add-sources-related");
gs_plugin_list_free (installed);
- if (results != NULL)
- g_object_unref (results);
return ret;
}
@@ -211,15 +199,13 @@ gs_plugin_add_sources (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
- GPtrArray *array = NULL;
- GsApp *app;
PkBitfield filter;
PkRepoDetail *rd;
- PkResults *results;
const gchar *id;
- gboolean ret = TRUE;
guint i;
- GHashTable *hash = NULL;
+ _cleanup_hashtable_unref_ GHashTable *hash = NULL;
+ _cleanup_object_unref_ PkResults *results = NULL;
+ _cleanup_ptrarray_unref_ GPtrArray *array = NULL;
/* ask PK for the repo details */
filter = pk_bitfield_from_enums (PK_FILTER_ENUM_NOT_SOURCE,
@@ -231,15 +217,14 @@ gs_plugin_add_sources (GsPlugin *plugin,
cancellable,
gs_plugin_packagekit_progress_cb, plugin,
error);
- if (results == NULL) {
- ret = FALSE;
- goto out;
- }
+ if (results == NULL)
+ return FALSE;
hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
array = pk_results_get_repo_detail_array (results);
+#if PK_CHECK_VERSION(0,9,1)
for (i = 0; i < array->len; i++) {
+ _cleanup_object_unref_ GsApp *app = NULL;
rd = g_ptr_array_index (array, i);
-#if PK_CHECK_VERSION(0,9,1)
id = pk_repo_detail_get_id (rd);
app = gs_app_new (id);
gs_app_set_management_plugin (app, "PackageKit");
@@ -255,23 +240,12 @@ gs_plugin_add_sources (GsPlugin *plugin,
g_hash_table_insert (hash,
g_strdup (id),
(gpointer) app);
- g_object_unref (app);
-#endif
}
+#endif
/* get every application on the system and add it as a related package
* if it matches */
- ret = gs_plugin_add_sources_related (plugin, hash, cancellable, error);
- if (!ret)
- goto out;
-out:
- if (hash != NULL)
- g_hash_table_unref (hash);
- if (array != NULL)
- g_ptr_array_unref (array);
- if (results != NULL)
- g_object_unref (results);
- return ret;
+ return gs_plugin_add_sources_related (plugin, hash, cancellable, error);
}
/**
@@ -467,8 +441,7 @@ gs_plugin_app_source_disable (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
- gboolean ret = TRUE;
- PkResults *results;
+ _cleanup_object_unref_ PkResults *results = NULL;
/* do sync call */
gs_plugin_status_update (plugin, NULL, GS_PLUGIN_STATUS_WAITING);
@@ -478,14 +451,7 @@ gs_plugin_app_source_disable (GsPlugin *plugin,
cancellable,
gs_plugin_packagekit_progress_cb, plugin,
error);
- if (results == NULL) {
- ret = FALSE;
- goto out;
- }
-out:
- if (results != NULL)
- g_object_unref (results);
- return ret;
+ return results != NULL;
}
/**
@@ -497,10 +463,9 @@ gs_plugin_app_source_remove (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
- gboolean ret = TRUE;
#if PK_CHECK_VERSION(0,9,1)
- PkResults *results;
- GError *error_local = NULL;
+ _cleanup_error_free_ GError *error_local = NULL;
+ _cleanup_object_unref_ PkResults *results = NULL;
/* do sync call */
gs_plugin_status_update (plugin, NULL, GS_PLUGIN_STATUS_WAITING);
@@ -515,20 +480,13 @@ gs_plugin_app_source_remove (GsPlugin *plugin,
/* fall back to disabling it */
g_warning ("ignoring source remove error, trying disable: %s",
error_local->message);
- g_error_free (error_local);
- ret = gs_plugin_app_source_disable (plugin,
- app,
- cancellable,
- error);
- goto out;
+ return gs_plugin_app_source_disable (plugin, app,
+ cancellable, error);
}
-out:
- if (results != NULL)
- g_object_unref (results);
+ return TRUE;
#else
- ret = gs_plugin_app_source_disable (plugin, app, cancellable, error);
+ return gs_plugin_app_source_disable (plugin, app, cancellable, error);
#endif
- return ret;
}
/**
@@ -541,37 +499,32 @@ gs_plugin_app_remove (GsPlugin *plugin,
GError **error)
{
const gchar *package_id;
- gchar **package_ids = NULL;
- gboolean ret = TRUE;
- GPtrArray *array = NULL;
- PkError *error_code = NULL;
- PkResults *results = NULL;
GPtrArray *source_ids;
guint i;
guint cnt = 0;
+ _cleanup_object_unref_ PkError *error_code = NULL;
+ _cleanup_object_unref_ PkResults *results = NULL;
+ _cleanup_ptrarray_unref_ GPtrArray *array = NULL;
+ _cleanup_strv_free_ gchar **package_ids = NULL;
/* only process this app if was created by this plugin */
if (g_strcmp0 (gs_app_get_management_plugin (app), "PackageKit") != 0)
- goto out;
+ return TRUE;
/* remove repo and all apps in it */
if (gs_app_get_kind (app) == GS_APP_KIND_SOURCE) {
- ret = gs_plugin_app_source_remove (plugin,
- app,
- cancellable,
- error);
- goto out;
+ return gs_plugin_app_source_remove (plugin, app,
+ cancellable, error);
}
/* get the list of available package ids to install */
source_ids = gs_app_get_source_ids (app);
if (source_ids->len == 0) {
- ret = FALSE;
g_set_error_literal (error,
GS_PLUGIN_ERROR,
GS_PLUGIN_ERROR_NOT_SUPPORTED,
"removing not available");
- goto out;
+ return FALSE;
}
package_ids = g_new0 (gchar *, source_ids->len + 1);
for (i = 0; i < source_ids->len; i++) {
@@ -581,12 +534,11 @@ gs_plugin_app_remove (GsPlugin *plugin,
package_ids[cnt++] = g_strdup (package_id);
}
if (cnt == 0) {
- ret = FALSE;
g_set_error_literal (error,
GS_PLUGIN_ERROR,
GS_PLUGIN_ERROR_NOT_SUPPORTED,
"no packages to remove");
- goto out;
+ return FALSE;
}
/* do the action */
@@ -597,10 +549,8 @@ gs_plugin_app_remove (GsPlugin *plugin,
cancellable,
gs_plugin_packagekit_progress_cb, plugin,
error);
- if (results == NULL) {
- ret = FALSE;
- goto out;
- }
+ if (results == NULL)
+ return FALSE;
/* no longer valid */
gs_app_clear_source_ids (app);
@@ -608,22 +558,13 @@ gs_plugin_app_remove (GsPlugin *plugin,
/* check error code */
error_code = pk_results_get_error_code (results);
if (error_code != NULL) {
- ret = FALSE;
g_set_error (error,
GS_PLUGIN_ERROR,
GS_PLUGIN_ERROR_FAILED,
"failed to remove package: %s, %s",
pk_error_enum_to_string (pk_error_get_code (error_code)),
pk_error_get_details (error_code));
- goto out;
+ return FALSE;
}
-out:
- g_strfreev (package_ids);
- if (error_code != NULL)
- g_object_unref (error_code);
- if (array != NULL)
- g_ptr_array_unref (array);
- if (results != NULL)
- g_object_unref (results);
- return ret;
+ return TRUE;
}
diff --git a/src/plugins/gs-plugin-systemd-updates.c b/src/plugins/gs-plugin-systemd-updates.c
index a9ec5a4..74598dd 100644
--- a/src/plugins/gs-plugin-systemd-updates.c
+++ b/src/plugins/gs-plugin-systemd-updates.c
@@ -97,19 +97,17 @@ gs_plugin_add_updates (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
- GError *error_local = NULL;
- GsApp *app;
- gboolean ret = TRUE;
- gchar **package_ids = NULL;
- gchar **split;
+ gboolean ret;
guint i;
+ _cleanup_error_free_ GError *error_local = NULL;
+ _cleanup_strv_free_ gchar **package_ids = NULL;
/* watch the file in case it comes or goes */
if (g_once_init_enter (&plugin->priv->done_init)) {
ret = gs_plugin_startup (plugin, cancellable, error);
g_once_init_leave (&plugin->priv->done_init, TRUE);
if (!ret)
- goto out;
+ return FALSE;
}
/* get the id's if the file exists */
@@ -119,16 +117,16 @@ gs_plugin_add_updates (GsPlugin *plugin,
PK_OFFLINE_ERROR,
PK_OFFLINE_ERROR_NO_DATA)) {
g_error_free (error_local);
- ret = TRUE;
- } else {
- g_propagate_error (error, error_local);
- ret = FALSE;
+ return TRUE;
}
- goto out;
+ g_propagate_error (error, error_local);
+ return FALSE;
}
/* add them to the new array */
for (i = 0; package_ids[i] != NULL; i++) {
+ _cleanup_object_unref_ GsApp *app = NULL;
+ _cleanup_strv_free_ gchar **split = NULL;
app = gs_app_new (NULL);
gs_app_set_management_plugin (app, "PackageKit");
gs_app_add_source_id (app, package_ids[i]);
@@ -138,10 +136,6 @@ gs_plugin_add_updates (GsPlugin *plugin,
gs_app_set_state (app, AS_APP_STATE_UPDATABLE);
gs_app_set_kind (app, GS_APP_KIND_PACKAGE);
gs_plugin_add_app (list, app);
- g_object_unref (app);
- g_strfreev (split);
}
-out:
- g_strfreev (package_ids);
- return ret;
+ return TRUE;
}
diff --git a/src/plugins/gs-self-test.c b/src/plugins/gs-self-test.c
index a863788..f5e1130 100644
--- a/src/plugins/gs-self-test.c
+++ b/src/plugins/gs-self-test.c
@@ -26,6 +26,7 @@
#include <glib-object.h>
#include <gtk/gtk.h>
+#include "gs-cleanup.h"
#include "gs-moduleset.h"
static void
@@ -34,7 +35,7 @@ moduleset_func (void)
gboolean ret;
gchar **data;
GError *error = NULL;
- GsModuleset *ms;
+ _cleanup_object_unref_ GsModuleset *ms = NULL;
/* not avaiable in make distcheck */
if (!g_file_test ("./moduleset-test.xml", G_FILE_TEST_EXISTS))
@@ -62,8 +63,6 @@ moduleset_func (void)
g_assert_cmpint (g_strv_length (data), ==, 1);
g_assert_cmpstr (data[0], ==, "gnome-shell.desktop");
g_assert_cmpstr (data[1], ==, NULL);
-
- g_object_unref (ms);
}
int
diff --git a/src/plugins/packagekit-common.c b/src/plugins/packagekit-common.c
index 9ac683d..548d5ed 100644
--- a/src/plugins/packagekit-common.c
+++ b/src/plugins/packagekit-common.c
@@ -92,26 +92,23 @@ gs_plugin_packagekit_add_results (GsPlugin *plugin,
GError **error)
{
const gchar *package_id;
- gboolean ret = TRUE;
- GHashTable *installed = NULL;
- GPtrArray *array = NULL;
- GPtrArray *array_filtered = NULL;
- GsApp *app;
guint i;
- PkError *error_code = NULL;
PkPackage *package;
+ _cleanup_hashtable_unref_ GHashTable *installed = NULL;
+ _cleanup_object_unref_ PkError *error_code = NULL;
+ _cleanup_ptrarray_unref_ GPtrArray *array_filtered = NULL;
+ _cleanup_ptrarray_unref_ GPtrArray *array = NULL;
/* check error code */
error_code = pk_results_get_error_code (results);
if (error_code != NULL) {
- ret = FALSE;
g_set_error (error,
GS_PLUGIN_ERROR,
GS_PLUGIN_ERROR_FAILED,
"failed to get-packages: %s, %s",
pk_error_enum_to_string (pk_error_get_code (error_code)),
pk_error_get_details (error_code));
- goto out;
+ return FALSE;
}
/* add all installed packages to a hash */
@@ -142,6 +139,7 @@ gs_plugin_packagekit_add_results (GsPlugin *plugin,
/* process packages */
for (i = 0; i < array_filtered->len; i++) {
+ _cleanup_object_unref_ GsApp *app = NULL;
package = g_ptr_array_index (array_filtered, i);
app = gs_app_new (NULL);
@@ -169,16 +167,6 @@ gs_plugin_packagekit_add_results (GsPlugin *plugin,
}
gs_app_set_kind (app, GS_APP_KIND_PACKAGE);
gs_plugin_add_app (list, app);
- g_object_unref (app);
}
-out:
- if (installed != NULL)
- g_hash_table_unref (installed);
- if (error_code != NULL)
- g_object_unref (error_code);
- if (array != NULL)
- g_ptr_array_unref (array);
- if (array_filtered != NULL)
- g_ptr_array_unref (array_filtered);
- return ret;
+ return TRUE;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]