[gnome-packagekit] trivial: Use g_autofree and g_autoptr in more places
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-packagekit] trivial: Use g_autofree and g_autoptr in more places
- Date: Mon, 18 Jul 2016 15:22:12 +0000 (UTC)
commit b679a86ff26cdc98dbd7cd4b27076f64eea430bf
Author: Richard Hughes <richard hughsie com>
Date: Mon Jul 18 15:08:07 2016 +0100
trivial: Use g_autofree and g_autoptr in more places
src/gpk-application.c | 517 ++++++++++++++----------------------------
src/gpk-cell-renderer-info.c | 12 +-
src/gpk-common.c | 51 ++---
src/gpk-dialog.c | 42 ++---
src/gpk-error.c | 13 +-
src/gpk-log.c | 82 +++-----
src/gpk-prefs.c | 88 +++-----
src/gpk-self-test.c | 22 +--
src/gpk-task.c | 94 +++------
src/gpk-update-viewer.c | 396 +++++++++++----------------------
src/systemd-proxy.c | 4 +-
11 files changed, 427 insertions(+), 894 deletions(-)
---
diff --git a/src/gpk-application.c b/src/gpk-application.c
index 3f10d28..84a7476 100644
--- a/src/gpk-application.c
+++ b/src/gpk-application.c
@@ -219,7 +219,7 @@ gpk_application_packages_checkbox_invert (GpkApplicationPrivate *priv)
GtkTreeSelection *selection;
PkBitfield state;
gboolean ret;
- gchar *package_id = NULL;
+ g_autofree gchar *package_id = NULL;
/* get the selection and add */
treeview = GTK_TREE_VIEW (gtk_builder_get_object (priv->builder, "treeview_packages"));
@@ -244,7 +244,6 @@ gpk_application_packages_checkbox_invert (GpkApplicationPrivate *priv)
PACKAGES_COLUMN_CHECKBOX, gpk_application_state_get_checkbox (state),
PACKAGES_COLUMN_IMAGE, gpk_application_state_get_icon (state),
-1);
- g_free (package_id);
}
static gboolean
@@ -278,7 +277,7 @@ gpk_application_get_selected_package (GpkApplicationPrivate *priv, gchar **packa
ret = gtk_tree_selection_get_selected (selection, &model, &iter);
if (!ret) {
g_warning ("no selection");
- goto out;
+ return FALSE;
}
/* get data */
@@ -292,25 +291,24 @@ gpk_application_get_selected_package (GpkApplicationPrivate *priv, gchar **packa
PACKAGES_COLUMN_SUMMARY, summary,
-1);
}
-out:
- return ret;
+ return TRUE;
}
static void
gpk_application_group_add_selected (GpkApplicationPrivate *priv)
{
gboolean ret;
- gchar *id = NULL;
+ g_autofree gchar *id = NULL;
GtkTreeIter iter;
ret = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (priv->groups_store), &iter);
if (!ret)
- goto out;
+ return;
gtk_tree_model_get (GTK_TREE_MODEL (priv->groups_store), &iter,
GROUPS_COLUMN_ID, &id,
-1);
if (g_strcmp0 (id, "selected") == 0)
- goto out;
+ return;
gtk_tree_store_insert (priv->groups_store, &iter, NULL, 0);
gtk_tree_store_set (priv->groups_store, &iter,
/* TRANSLATORS: this is a menu group of packages in the queue */
@@ -320,28 +318,24 @@ gpk_application_group_add_selected (GpkApplicationPrivate *priv)
GROUPS_COLUMN_ICON, "edit-find",
GROUPS_COLUMN_ACTIVE, TRUE,
-1);
-out:
- g_free (id);
}
static void
gpk_application_group_remove_selected (GpkApplicationPrivate *priv)
{
gboolean ret;
- gchar *id = NULL;
+ g_autofree gchar *id = NULL;
GtkTreeIter iter;
ret = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (priv->groups_store), &iter);
if (!ret)
- goto out;
+ return;
gtk_tree_model_get (GTK_TREE_MODEL (priv->groups_store), &iter,
GROUPS_COLUMN_ID, &id,
-1);
if (g_strcmp0 (id, "selected") != 0)
- goto out;
+ return;
gtk_tree_store_remove (priv->groups_store, &iter);
-out:
- g_free (id);
}
static void
@@ -354,7 +348,6 @@ gpk_application_change_queue_status (GpkApplicationPrivate *priv)
GtkTreeModel *model;
PkBitfield state;
gboolean enabled;
- gchar *package_id;
/* show and hide the action widgets */
if (pk_package_sack_get_size (priv->package_sack) > 0) {
@@ -379,6 +372,7 @@ gpk_application_change_queue_status (GpkApplicationPrivate *priv)
/* for all current items, reset the state if in the array */
while (valid) {
+ g_autofree gchar *package_id = NULL;
gtk_tree_model_get (model, &iter,
PACKAGES_COLUMN_STATE, &state,
PACKAGES_COLUMN_ID, &package_id,
@@ -390,7 +384,6 @@ gpk_application_change_queue_status (GpkApplicationPrivate *priv)
} else {
enabled = gpk_application_get_checkbox_enable (priv, state);
}
- g_free (package_id);
/* set visible */
gtk_list_store_set (GTK_LIST_STORE (model), &iter, PACKAGES_COLUMN_CHECKBOX_VISIBLE, enabled,
-1);
@@ -402,9 +395,9 @@ static gboolean
gpk_application_install (GpkApplicationPrivate *priv)
{
gboolean ret;
- gchar *package_id_selected = NULL;
- gchar *summary_selected = NULL;
- PkPackage *package;
+ g_autofree gchar *package_id_selected = NULL;
+ g_autofree gchar *summary_selected = NULL;
+ g_autoptr(PkPackage) package = NULL;
/* get selection */
ret = gpk_application_get_selected_package (priv, &package_id_selected, &summary_selected);
@@ -449,7 +442,6 @@ gpk_application_install (GpkApplicationPrivate *priv)
"summary", summary_selected,
NULL);
pk_package_sack_add_package (priv->package_sack, package);
- g_object_unref (package);
/* correct buttons */
gpk_application_allow_install (priv, FALSE);
@@ -458,9 +450,6 @@ gpk_application_install (GpkApplicationPrivate *priv)
out:
/* add the selected group if there are any packages in the queue */
gpk_application_change_queue_status (priv);
-
- g_free (package_id_selected);
- g_free (summary_selected);
return ret;
}
@@ -480,25 +469,24 @@ static void
gpk_application_get_files_cb (PkClient *client, GAsyncResult *res, GpkApplicationPrivate *priv)
{
gboolean ret;
- gchar **files = NULL;
- gchar *package_id_selected = NULL;
- gchar **split = NULL;
- gchar *title = NULL;
- GError *error = NULL;
- GPtrArray *array = NULL;
- GPtrArray *array_sort = NULL;
+ g_auto(GStrv) files = NULL;
+ g_autofree gchar *package_id_selected = NULL;
+ g_auto(GStrv) split = NULL;
+ g_autofree gchar *title = NULL;
+ g_autoptr(GError) error = NULL;
+ g_autoptr(GPtrArray) array = NULL;
+ g_autoptr(GPtrArray) array_sort = NULL;
GtkWidget *dialog;
GtkWindow *window;
- PkError *error_code = NULL;
+ g_autoptr(PkError) error_code = NULL;
PkFiles *item;
- PkResults *results;
+ g_autoptr(PkResults) results = NULL;
/* get the results */
results = pk_client_generic_finish (client, res, &error);
if (results == NULL) {
g_warning ("failed to get files: %s", error->message);
- g_error_free (error);
- goto out;
+ return;
}
/* check error code */
@@ -512,13 +500,13 @@ gpk_application_get_files_cb (PkClient *client, GAsyncResult *res, GpkApplicatio
gpk_error_dialog_modal (window, gpk_error_enum_to_localised_text (pk_error_get_code
(error_code)),
gpk_error_enum_to_localised_message (pk_error_get_code
(error_code)), pk_error_get_details (error_code));
}
- goto out;
+ return;
}
/* get data */
array = pk_results_get_files_array (results);
if (array->len != 1)
- goto out;
+ return;
/* assume only one option */
item = g_ptr_array_index (array, 0);
@@ -527,7 +515,7 @@ gpk_application_get_files_cb (PkClient *client, GAsyncResult *res, GpkApplicatio
ret = gpk_application_get_selected_package (priv, &package_id_selected, NULL);
if (!ret) {
g_warning ("no package selected");
- goto out;
+ return;
}
/* get data */
@@ -555,19 +543,6 @@ gpk_application_get_files_cb (PkClient *client, GAsyncResult *res, GpkApplicatio
gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_destroy (GTK_WIDGET (dialog));
-out:
- g_free (title);
- g_strfreev (files);
- g_strfreev (split);
- g_free (package_id_selected);
- if (error_code != NULL)
- g_object_unref (error_code);
- if (array != NULL)
- g_ptr_array_unref (array);
- if (array_sort != NULL)
- g_ptr_array_unref (array_sort);
- if (results != NULL)
- g_object_unref (results);
}
static gboolean
@@ -635,12 +610,12 @@ gpk_application_progress_cb (PkProgress *progress, PkProgressType type, GpkAppli
gtk_widget_hide (widget);
widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "progressbar_progress"));
gtk_widget_hide (widget);
- goto out;
+ return;
}
/* already pending show */
if (priv->status_id > 0)
- goto out;
+ return;
/* only show after some time in the transaction */
priv->status_id =
@@ -665,22 +640,20 @@ gpk_application_progress_cb (PkProgress *progress, PkProgressType type, GpkAppli
widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "button_cancel"));
gtk_widget_set_sensitive (widget, allow_cancel);
}
-out:
- return;
}
static void
gpk_application_menu_files_cb (GtkAction *action, GpkApplicationPrivate *priv)
{
gboolean ret;
- gchar **package_ids = NULL;
- gchar *package_id_selected = NULL;
+ g_auto(GStrv) package_ids = NULL;
+ g_autofree gchar *package_id_selected = NULL;
/* get selection */
ret = gpk_application_get_selected_package (priv, &package_id_selected, NULL);
if (!ret) {
g_warning ("no package selected");
- goto out;
+ return;
}
/* ensure new action succeeds */
@@ -691,18 +664,15 @@ gpk_application_menu_files_cb (GtkAction *action, GpkApplicationPrivate *priv)
pk_client_get_files_async (PK_CLIENT (priv->task), package_ids, priv->cancellable,
(PkProgressCallback) gpk_application_progress_cb, priv,
(GAsyncReadyCallback) gpk_application_get_files_cb, priv);
-out:
- g_free (package_id_selected);
- g_strfreev (package_ids);
}
static gboolean
gpk_application_remove (GpkApplicationPrivate *priv)
{
gboolean ret;
- gchar *package_id_selected = NULL;
- gchar *summary_selected = NULL;
- PkPackage *package;
+ g_autofree gchar *package_id_selected = NULL;
+ g_autofree gchar *summary_selected = NULL;
+ g_autoptr(PkPackage) package = NULL;
/* get selection */
ret = gpk_application_get_selected_package (priv, &package_id_selected, &summary_selected);
@@ -744,7 +714,6 @@ gpk_application_remove (GpkApplicationPrivate *priv)
"summary", summary_selected,
NULL);
pk_package_sack_add_package (priv->package_sack, package);
- g_object_unref (package);
/* correct buttons */
gpk_application_allow_install (priv, TRUE);
@@ -753,8 +722,6 @@ gpk_application_remove (GpkApplicationPrivate *priv)
out:
/* add the selected group if there are any packages in the queue */
gpk_application_change_queue_status (priv);
- g_free (package_id_selected);
- g_free (summary_selected);
return TRUE;
}
@@ -773,25 +740,24 @@ gpk_application_menu_remove_cb (GtkAction *action, GpkApplicationPrivate *priv)
static void
gpk_application_get_requires_cb (PkClient *client, GAsyncResult *res, GpkApplicationPrivate *priv)
{
- PkResults *results;
- GError *error = NULL;
- PkError *error_code = NULL;
- GPtrArray *array = NULL;
+ g_autoptr(PkResults) results = NULL;
+ g_autoptr(GError) error = NULL;
+ g_autoptr(PkError) error_code = NULL;
+ g_autoptr(GPtrArray) array = NULL;
GtkWindow *window;
- gchar *name = NULL;
- gchar *title = NULL;
- gchar *message = NULL;
- gchar **package_ids = NULL;
+ g_autofree gchar *name = NULL;
+ g_autofree gchar *title = NULL;
+ g_autofree gchar *message = NULL;
+ g_auto(GStrv) package_ids = NULL;
GtkWidget *dialog;
- gchar *package_id_selected = NULL;
+ g_autofree gchar *package_id_selected = NULL;
gboolean ret;
/* get the results */
results = pk_client_generic_finish (client, res, &error);
if (results == NULL) {
g_warning ("failed to get requires: %s", error->message);
- g_error_free (error);
- goto out;
+ return;
}
/* check error code */
@@ -805,14 +771,14 @@ gpk_application_get_requires_cb (PkClient *client, GAsyncResult *res, GpkApplica
gpk_error_dialog_modal (window, gpk_error_enum_to_localised_text (pk_error_get_code
(error_code)),
gpk_error_enum_to_localised_message (pk_error_get_code
(error_code)), pk_error_get_details (error_code));
}
- goto out;
+ return;
}
/* get selection */
ret = gpk_application_get_selected_package (priv, &package_id_selected, NULL);
if (!ret) {
g_warning ("no package selected");
- goto out;
+ return;
}
/* get data */
@@ -826,7 +792,7 @@ gpk_application_get_requires_cb (PkClient *client, GAsyncResult *res, GpkApplica
_("No packages"),
/* TRANSLATORS: this package is not required by any others */
_("No other packages require this package"), NULL);
- goto out;
+ return;
}
package_ids = pk_package_ids_from_id (package_id_selected);
@@ -849,32 +815,20 @@ gpk_application_get_requires_cb (PkClient *client, GAsyncResult *res, GpkApplica
gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_destroy (GTK_WIDGET (dialog));
-out:
- g_free (package_id_selected);
- g_strfreev (package_ids);
- g_free (name);
- g_free (title);
- g_free (message);
- 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
gpk_application_menu_requires_cb (GtkAction *action, GpkApplicationPrivate *priv)
{
gboolean ret;
- gchar **package_ids = NULL;
- gchar *package_id_selected = NULL;
+ g_auto(GStrv) package_ids = NULL;
+ g_autofree gchar *package_id_selected = NULL;
/* get selection */
ret = gpk_application_get_selected_package (priv, &package_id_selected, NULL);
if (!ret) {
g_warning ("no package selected");
- goto out;
+ return;
}
/* ensure new action succeeds */
@@ -888,34 +842,29 @@ gpk_application_menu_requires_cb (GtkAction *action, GpkApplicationPrivate *priv
package_ids, TRUE, priv->cancellable,
(PkProgressCallback) gpk_application_progress_cb, priv,
(GAsyncReadyCallback) gpk_application_get_depends_cb, priv);
-
-out:
- g_free (package_id_selected);
- g_strfreev (package_ids);
}
static void
gpk_application_get_depends_cb (PkClient *client, GAsyncResult *res, GpkApplicationPrivate *priv)
{
- PkResults *results;
- GError *error = NULL;
- PkError *error_code = NULL;
- GPtrArray *array = NULL;
+ g_autoptr(PkResults) results = NULL;
+ g_autoptr(GError) error = NULL;
+ g_autoptr(PkError) error_code = NULL;
+ g_autoptr(GPtrArray) array = NULL;
GtkWindow *window;
- gchar *name = NULL;
- gchar *title = NULL;
- gchar *message = NULL;
- gchar **package_ids = NULL;
+ g_autofree gchar *name = NULL;
+ g_autofree gchar *title = NULL;
+ g_autofree gchar *message = NULL;
+ g_auto(GStrv) package_ids = NULL;
GtkWidget *dialog;
- gchar *package_id_selected = NULL;
+ g_autofree gchar *package_id_selected = NULL;
gboolean ret;
/* get the results */
results = pk_client_generic_finish (client, res, &error);
if (results == NULL) {
g_warning ("failed to get depends: %s", error->message);
- g_error_free (error);
- goto out;
+ return;
}
/* check error code */
@@ -929,7 +878,7 @@ gpk_application_get_depends_cb (PkClient *client, GAsyncResult *res, GpkApplicat
gpk_error_dialog_modal (window, gpk_error_enum_to_localised_text (pk_error_get_code
(error_code)),
gpk_error_enum_to_localised_message (pk_error_get_code
(error_code)), pk_error_get_details (error_code));
}
- goto out;
+ return;
}
/* get data */
@@ -939,7 +888,7 @@ gpk_application_get_depends_cb (PkClient *client, GAsyncResult *res, GpkApplicat
ret = gpk_application_get_selected_package (priv, &package_id_selected, NULL);
if (!ret) {
g_warning ("no package selected");
- goto out;
+ return;
}
/* empty array */
@@ -950,7 +899,7 @@ gpk_application_get_depends_cb (PkClient *client, GAsyncResult *res, GpkApplicat
_("No packages"),
/* TRANSLATORS: this package does not depend on any others */
_("This package does not depend on any others"), NULL);
- goto out;
+ return;
}
package_ids = pk_package_ids_from_id (package_id_selected);
@@ -973,32 +922,20 @@ gpk_application_get_depends_cb (PkClient *client, GAsyncResult *res, GpkApplicat
gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_destroy (GTK_WIDGET (dialog));
-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);
- g_free (package_id_selected);
- g_strfreev (package_ids);
- g_free (name);
- g_free (title);
- g_free (message);
}
static void
gpk_application_menu_depends_cb (GtkAction *_action, GpkApplicationPrivate *priv)
{
gboolean ret;
- gchar **package_ids = NULL;
- gchar *package_id_selected = NULL;
+ g_auto(GStrv) package_ids = NULL;
+ g_autofree gchar *package_id_selected = NULL;
/* get selection */
ret = gpk_application_get_selected_package (priv, &package_id_selected, NULL);
if (!ret) {
g_warning ("no package selected");
- goto out;
+ return;
}
/* ensure new action succeeds */
@@ -1012,10 +949,6 @@ gpk_application_menu_depends_cb (GtkAction *_action, GpkApplicationPrivate *priv
package_ids, TRUE, priv->cancellable,
(PkProgressCallback) gpk_application_progress_cb, priv,
(GAsyncReadyCallback) gpk_application_get_requires_cb, priv);
-
-out:
- g_free (package_id_selected);
- g_strfreev (package_ids);
}
static const gchar *
@@ -1077,15 +1010,15 @@ static void
gpk_application_add_item_to_results (GpkApplicationPrivate *priv, PkPackage *item)
{
GtkTreeIter iter;
- gchar *text;
+ g_autofree gchar *text = NULL;
gboolean in_queue;
gboolean installed;
gboolean enabled;
PkBitfield state = 0;
static guint package_cnt = 0;
PkInfoEnum info;
- gchar *package_id = NULL;
- gchar *summary = NULL;
+ g_autofree gchar *package_id = NULL;
+ g_autofree gchar *summary = NULL;
GtkWidget *widget;
/* get data */
@@ -1136,10 +1069,6 @@ gpk_application_add_item_to_results (GpkApplicationPrivate *priv, PkPackage *ite
while (gtk_events_pending ())
gtk_main_iteration ();
}
-
- g_free (package_id);
- g_free (summary);
- g_free (text);
}
static void
@@ -1149,7 +1078,7 @@ gpk_application_suggest_better_search (GpkApplicationPrivate *priv)
/* TRANSLATORS: no results were found for this search */
const gchar *title = _("No results were found.");
GtkTreeIter iter;
- gchar *text;
+ g_autofree gchar *text = NULL;
PkBitfield state = 0;
if (priv->search_mode == GPK_MODE_GROUP ||
@@ -1179,7 +1108,6 @@ gpk_application_suggest_better_search (GpkApplicationPrivate *priv)
PACKAGES_COLUMN_IMAGE, "system-search",
PACKAGES_COLUMN_ID, NULL,
-1);
- g_free (text);
}
static gboolean
@@ -1204,8 +1132,6 @@ gpk_application_select_exact_match (GpkApplicationPrivate *priv, const gchar *te
GtkTreePath *path;
GtkTreeModel *model;
GtkTreeSelection *selection = NULL;
- gchar *package_id;
- gchar **split;
/* get the first iter in the array */
treeview = GTK_TREE_VIEW (gtk_builder_get_object (priv->builder, "treeview_packages"));
@@ -1214,8 +1140,10 @@ gpk_application_select_exact_match (GpkApplicationPrivate *priv, const gchar *te
/* for all items in treeview */
while (valid) {
+ g_autofree gchar *package_id = NULL;
gtk_tree_model_get (model, &iter, PACKAGES_COLUMN_ID, &package_id, -1);
if (package_id != NULL) {
+ g_auto(GStrv) split = NULL;
/* exact match, so select and scroll */
split = pk_package_id_split (package_id);
if (g_strcmp0 (split[PK_PACKAGE_ID_NAME], text) == 0) {
@@ -1225,28 +1153,15 @@ gpk_application_select_exact_match (GpkApplicationPrivate *priv, const gchar *te
gtk_tree_view_scroll_to_cell (treeview, path, NULL, FALSE, 0.5f, 0.5f);
gtk_tree_path_free (path);
}
- g_strfreev (split);
/* no point continuing for a second match */
if (selection != NULL)
break;
}
- g_free (package_id);
valid = gtk_tree_model_iter_next (model, &iter);
}
}
-#if 0
-static void
-gpk_application_finished_cb (PkClient *client, PkExitEnum exit_enum, guint runtime, GpkApplicationPrivate
*priv)
-{
-
-// widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "progressbar_progress"));
-// gtk_widget_hide (widget);
-
-}
-#endif
-
static void
gpk_application_cancel_cb (GtkWidget *button_widget, GpkApplicationPrivate *priv)
{
@@ -1269,10 +1184,10 @@ gpk_application_set_button_find_sensitivity (GpkApplicationPrivate *priv)
static void
gpk_application_search_cb (PkClient *client, GAsyncResult *res, GpkApplicationPrivate *priv)
{
- PkResults *results;
- GError *error = NULL;
- PkError *error_code = NULL;
- GPtrArray *array = NULL;
+ g_autoptr(PkResults) results = NULL;
+ g_autoptr(GError) error = NULL;
+ g_autoptr(PkError) error_code = NULL;
+ g_autoptr(GPtrArray) array = NULL;
PkPackage *item;
guint i;
GtkWidget *widget;
@@ -1282,7 +1197,6 @@ gpk_application_search_cb (PkClient *client, GAsyncResult *res, GpkApplicationPr
results = pk_client_generic_finish (client, res, &error);
if (results == NULL) {
g_warning ("failed to search: %s", error->message);
- g_error_free (error);
goto out;
}
@@ -1302,7 +1216,7 @@ gpk_application_search_cb (PkClient *client, GAsyncResult *res, GpkApplicationPr
/* get data */
array = pk_results_get_package_array (results);
- for (i=0; i<array->len; i++) {
+ for (i = 0; i < array->len; i++) {
item = g_ptr_array_index (array, i);
gpk_application_add_item_to_results (priv, item);
}
@@ -1333,13 +1247,6 @@ out:
gpk_application_set_button_find_sensitivity (priv);
widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "scrolledwindow_groups"));
gtk_widget_set_sensitive (widget, TRUE);
-
- 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
@@ -1347,9 +1254,9 @@ gpk_application_perform_search_name_details_file (GpkApplicationPrivate *priv)
{
GtkEntry *entry;
GtkWindow *window;
- GError *error = NULL;
+ g_autoptr(GError) error = NULL;
gboolean ret;
- gchar **searches = NULL;
+ g_auto(GStrv) searches = NULL;
entry = GTK_ENTRY (gtk_builder_get_object (priv->builder, "entry_text"));
g_free (priv->search_text);
@@ -1358,7 +1265,7 @@ gpk_application_perform_search_name_details_file (GpkApplicationPrivate *priv)
/* have we got input? */
if (_g_strzero (priv->search_text)) {
g_debug ("no input");
- goto out;
+ return;
}
ret = !_g_strzero (priv->search_text);
@@ -1371,7 +1278,7 @@ gpk_application_perform_search_name_details_file (GpkApplicationPrivate *priv)
_("Invalid search text"),
/* TRANSLATORS: message: tell the user that's not allowed */
_("The search text contains invalid characters"), NULL);
- goto out;
+ return;
}
g_debug ("find %s", priv->search_text);
@@ -1404,7 +1311,7 @@ gpk_application_perform_search_name_details_file (GpkApplicationPrivate *priv)
(GAsyncReadyCallback) gpk_application_search_cb, priv);
} else {
g_warning ("invalid search type");
- goto out;
+ return;
}
if (!ret) {
@@ -1414,30 +1321,25 @@ gpk_application_perform_search_name_details_file (GpkApplicationPrivate *priv)
_("The search could not be completed"),
/* TRANSLATORS: low level failure, details to follow */
_("Running the transaction failed"), error->message);
- g_error_free (error);
- goto out;
+ return;
}
-out:
- g_strfreev (searches);
}
static void
gpk_application_perform_search_others (GpkApplicationPrivate *priv)
{
- gchar **search_groups;
-
/* ensure new action succeeds */
g_cancellable_reset (priv->cancellable);
priv->search_in_progress = TRUE;
if (priv->search_mode == GPK_MODE_GROUP) {
+ g_auto(GStrv) search_groups = NULL;
search_groups = g_strsplit (priv->search_group, " ", -1);
pk_client_search_groups_async (PK_CLIENT(priv->task),
priv->filters_current, search_groups, priv->cancellable,
(PkProgressCallback) gpk_application_progress_cb, priv,
(GAsyncReadyCallback) gpk_application_search_cb, priv);
- g_strfreev (search_groups);
} else {
pk_client_get_packages_async (PK_CLIENT(priv->task),
priv->filters_current, priv->cancellable,
@@ -1451,7 +1353,7 @@ gpk_application_populate_selected (GpkApplicationPrivate *priv)
{
guint i;
PkPackage *package;
- GPtrArray *array;
+ g_autoptr(GPtrArray) array = NULL;
/* get size */
array = pk_package_sack_get_array (priv->package_sack);
@@ -1459,17 +1361,14 @@ gpk_application_populate_selected (GpkApplicationPrivate *priv)
/* nothing in queue */
if (array->len == 0) {
gpk_application_suggest_better_search (priv);
- goto out;
+ return TRUE;
}
/* dump queue to package window */
- for (i=0; i<array->len; i++) {
+ for (i = 0; i < array->len; i++) {
package = g_ptr_array_index (array, i);
gpk_application_add_item_to_results (priv, package);
}
-
-out:
- g_ptr_array_unref (array);
return TRUE;
}
@@ -1510,7 +1409,7 @@ gpk_application_find_cb (GtkWidget *button_widget, GpkApplicationPrivate *priv)
static gboolean
gpk_application_quit (GpkApplicationPrivate *priv)
{
- GPtrArray *array;
+ g_autoptr(GPtrArray) array = NULL;
gint len;
GtkResponseType result;
GtkWindow *window;
@@ -1519,7 +1418,6 @@ gpk_application_quit (GpkApplicationPrivate *priv)
/* do we have any items queued for removal or installation? */
array = pk_package_sack_get_array (priv->package_sack);
len = array->len;
- g_ptr_array_unref (array);
if (len != 0) {
window = GTK_WINDOW (gtk_builder_get_object (priv->builder, "window_manager"));
@@ -1653,9 +1551,9 @@ gpk_application_button_clear_cb (GtkWidget *widget_button, GpkApplicationPrivate
static void
gpk_application_install_packages_cb (PkTask *task, GAsyncResult *res, GpkApplicationPrivate *priv)
{
- PkResults *results;
- GError *error = NULL;
- PkError *error_code = NULL;
+ g_autoptr(PkResults) results = NULL;
+ g_autoptr(GError) error = NULL;
+ g_autoptr(PkError) error_code = NULL;
GtkWindow *window;
guint idle_id;
@@ -1663,8 +1561,7 @@ gpk_application_install_packages_cb (PkTask *task, GAsyncResult *res, GpkApplica
results = pk_task_generic_finish (task, res, &error);
if (results == NULL) {
g_warning ("failed to install packages: %s", error->message);
- g_error_free (error);
- goto out;
+ return;
}
/* check error code */
@@ -1678,7 +1575,7 @@ gpk_application_install_packages_cb (PkTask *task, GAsyncResult *res, GpkApplica
gpk_error_dialog_modal (window, gpk_error_enum_to_localised_text (pk_error_get_code
(error_code)),
gpk_error_enum_to_localised_message (pk_error_get_code
(error_code)), pk_error_get_details (error_code));
}
- goto out;
+ return;
}
/* idle add in the background */
@@ -1689,19 +1586,14 @@ gpk_application_install_packages_cb (PkTask *task, GAsyncResult *res, GpkApplica
pk_package_sack_clear (priv->package_sack);
priv->action = GPK_ACTION_NONE;
gpk_application_change_queue_status (priv);
-out:
- if (error_code != NULL)
- g_object_unref (error_code);
- if (results != NULL)
- g_object_unref (results);
}
static void
gpk_application_remove_packages_cb (PkTask *task, GAsyncResult *res, GpkApplicationPrivate *priv)
{
- PkResults *results;
- GError *error = NULL;
- PkError *error_code = NULL;
+ g_autoptr(PkResults) results = NULL;
+ g_autoptr(GError) error = NULL;
+ g_autoptr(PkError) error_code = NULL;
GtkWindow *window;
guint idle_id;
@@ -1709,8 +1601,7 @@ gpk_application_remove_packages_cb (PkTask *task, GAsyncResult *res, GpkApplicat
results = pk_task_generic_finish (task, res, &error);
if (results == NULL) {
g_warning ("failed to remove packages: %s", error->message);
- g_error_free (error);
- goto out;
+ return;
}
/* check error code */
@@ -1724,7 +1615,7 @@ gpk_application_remove_packages_cb (PkTask *task, GAsyncResult *res, GpkApplicat
gpk_error_dialog_modal (window, gpk_error_enum_to_localised_text (pk_error_get_code
(error_code)),
gpk_error_enum_to_localised_message (pk_error_get_code
(error_code)), pk_error_get_details (error_code));
}
- goto out;
+ return;
}
/* idle add in the background */
@@ -1735,17 +1626,12 @@ gpk_application_remove_packages_cb (PkTask *task, GAsyncResult *res, GpkApplicat
pk_package_sack_clear (priv->package_sack);
priv->action = GPK_ACTION_NONE;
gpk_application_change_queue_status (priv);
-out:
- if (error_code != NULL)
- g_object_unref (error_code);
- if (results != NULL)
- g_object_unref (results);
}
static void
gpk_application_button_apply_cb (GtkWidget *widget, GpkApplicationPrivate *priv)
{
- gchar **package_ids = NULL;
+ g_auto(GStrv) package_ids = NULL;
gboolean autoremove;
/* ensure new action succeeds */
@@ -1786,8 +1672,6 @@ gpk_application_button_apply_cb (GtkWidget *widget, GpkApplicationPrivate *priv)
widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "button_clear"));
gtk_widget_set_visible (widget, FALSE);
}
- g_strfreev (package_ids);
- return;
}
static void
@@ -1902,30 +1786,29 @@ gpk_application_groups_treeview_changed_cb (GtkTreeSelection *selection, GpkAppl
static void
gpk_application_get_details_cb (PkClient *client, GAsyncResult *res, GpkApplicationPrivate *priv)
{
- PkResults *results;
- GError *error = NULL;
- PkError *error_code = NULL;
- GPtrArray *array = NULL;
+ g_autoptr(PkResults) results = NULL;
+ g_autoptr(GError) error = NULL;
+ g_autoptr(PkError) error_code = NULL;
+ g_autoptr(GPtrArray) array = NULL;
PkDetails *item;
GtkWidget *widget;
gchar *value;
const gchar *repo_name;
gboolean installed;
- gchar **split = NULL;
+ g_auto(GStrv) split = NULL;
GtkWindow *window;
- gchar *package_id = NULL;
- gchar *url = NULL;
+ g_autofree gchar *package_id = NULL;
+ g_autofree gchar *url = NULL;
PkGroupEnum group;
- gchar *license = NULL;
- gchar *description = NULL;
+ g_autofree gchar *license = NULL;
+ g_autofree gchar *description = NULL;
guint64 size;
/* get the results */
results = pk_client_generic_finish (client, res, &error);
if (results == NULL) {
g_warning ("failed to get list of categories: %s", error->message);
- g_error_free (error);
- goto out;
+ return;
}
/* check error code */
@@ -1939,14 +1822,14 @@ gpk_application_get_details_cb (PkClient *client, GAsyncResult *res, GpkApplicat
gpk_error_dialog_modal (window, gpk_error_enum_to_localised_text (pk_error_get_code
(error_code)),
gpk_error_enum_to_localised_message (pk_error_get_code
(error_code)), pk_error_get_details (error_code));
}
- goto out;
+ return;
}
/* get data */
array = pk_results_get_details_array (results);
if (array->len != 1) {
g_warning ("not one entry %i", array->len);
- goto out;
+ return;
}
/* only choose the first item */
@@ -2036,18 +1919,6 @@ gpk_application_get_details_cb (PkClient *client, GAsyncResult *res, GpkApplicat
widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "label_source"));
gtk_widget_hide (widget);
}
-out:
- g_free (package_id);
- g_free (url);
- g_free (license);
- g_free (description);
- g_strfreev (split);
- 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
@@ -2059,9 +1930,9 @@ gpk_application_packages_treeview_clicked_cb (GtkTreeSelection *selection, GpkAp
gboolean show_install = TRUE;
gboolean show_remove = TRUE;
PkBitfield state;
- gchar **package_ids = NULL;
- gchar *package_id = NULL;
- gchar *summary = NULL;
+ g_auto(GStrv) package_ids = NULL;
+ g_autofree gchar *package_id = NULL;
+ g_autofree gchar *summary = NULL;
/* ignore selection changed if we've just cleared the package list */
if (!priv->has_package)
@@ -2079,7 +1950,7 @@ gpk_application_packages_treeview_clicked_cb (GtkTreeSelection *selection, GpkAp
/* hide details */
gpk_application_clear_details (priv);
- goto out;
+ return;
}
/* check we aren't a help line */
@@ -2090,7 +1961,7 @@ gpk_application_packages_treeview_clicked_cb (GtkTreeSelection *selection, GpkAp
-1);
if (package_id == NULL) {
g_debug ("ignoring help click");
- goto out;
+ return;
}
/* set the summary as we know it already */
@@ -2127,10 +1998,6 @@ gpk_application_packages_treeview_clicked_cb (GtkTreeSelection *selection, GpkAp
pk_client_get_details_async (PK_CLIENT(priv->task), package_ids, priv->cancellable,
(PkProgressCallback) gpk_application_progress_cb, priv,
(GAsyncReadyCallback) gpk_application_get_details_cb, priv);
-out:
- g_free (package_id);
- g_free (summary);
- g_strfreev (package_ids);
}
static void
@@ -2305,7 +2172,7 @@ gpk_application_activate_about_cb (GSimpleAction *action,
};
/* TRANSLATORS: put your own name here -- you deserve credit! */
const char *translators = _("translator-credits");
- char *license_trans;
+ g_autofree gchar *license_trans = NULL;
/* Translators comment: put your own name here to appear in the about dialog. */
if (!strcmp (translators, "translator-credits")) {
@@ -2334,7 +2201,6 @@ gpk_application_activate_about_cb (GSimpleAction *action,
"translator-credits", translators,
"logo-icon-name", GPK_ICON_SOFTWARE_INSTALLER,
NULL);
- g_free (license_trans);
}
static void
@@ -2343,7 +2209,7 @@ gpk_application_activate_sources_cb (GSimpleAction *action,
gpointer user_data)
{
gboolean ret;
- gchar *command;
+ g_autofree gchar *command = NULL;
GpkApplicationPrivate *priv = user_data;
GtkWidget *window;
guint xid;
@@ -2355,10 +2221,8 @@ gpk_application_activate_sources_cb (GSimpleAction *action,
command = g_strdup_printf ("%s/gpk-prefs --parent-window %u", BINDIR, xid);
g_debug ("running: %s", command);
ret = g_spawn_command_line_async (command, NULL);
- if (!ret) {
+ if (!ret)
g_warning ("spawn of %s failed", command);
- }
- g_free (command);
}
static void
@@ -2367,7 +2231,7 @@ gpk_application_activate_log_cb (GSimpleAction *action,
gpointer user_data)
{
gboolean ret;
- gchar *command;
+ g_autofree gchar *command = NULL;
GpkApplicationPrivate *priv = user_data;
GtkWidget *window;
guint xid;
@@ -2379,26 +2243,23 @@ gpk_application_activate_log_cb (GSimpleAction *action,
command = g_strdup_printf ("%s/gpk-log --parent-window %u", BINDIR, xid);
g_debug ("running: %s", command);
ret = g_spawn_command_line_async (command, NULL);
- if (!ret) {
+ if (!ret)
g_warning ("spawn of %s failed", command);
- }
- g_free (command);
}
static void
gpk_application_refresh_cache_cb (PkClient *client, GAsyncResult *res, GpkApplicationPrivate *priv)
{
- PkResults *results;
- GError *error = NULL;
- PkError *error_code = NULL;
+ g_autoptr(PkResults) results = NULL;
+ g_autoptr(GError) error = NULL;
+ g_autoptr(PkError) error_code = NULL;
GtkWindow *window;
/* get the results */
results = pk_client_generic_finish (client, res, &error);
if (results == NULL) {
g_warning ("failed to refresh: %s", error->message);
- g_error_free (error);
- goto out;
+ return;
}
/* check error code */
@@ -2412,13 +2273,8 @@ gpk_application_refresh_cache_cb (PkClient *client, GAsyncResult *res, GpkApplic
gpk_error_dialog_modal (window, gpk_error_enum_to_localised_text (pk_error_get_code
(error_code)),
gpk_error_enum_to_localised_message (pk_error_get_code
(error_code)), pk_error_get_details (error_code));
}
- goto out;
+ return;
}
-out:
- if (error_code != NULL)
- g_object_unref (error_code);
- if (results != NULL)
- g_object_unref (results);
}
static void
@@ -2444,7 +2300,7 @@ gpk_application_package_row_activated_cb (GtkTreeView *treeview, GtkTreePath *pa
GtkTreeIter iter;
gboolean ret;
PkBitfield state;
- gchar *package_id = NULL;
+ g_autofree gchar *package_id = NULL;
/* get selection */
model = gtk_tree_view_get_model (treeview);
@@ -2463,26 +2319,21 @@ gpk_application_package_row_activated_cb (GtkTreeView *treeview, GtkTreePath *pa
/* check we aren't a help line */
if (package_id == NULL) {
g_debug ("ignoring help click");
- goto out;
+ return;
}
if (gpk_application_state_get_checkbox (state))
gpk_application_remove (priv);
else
gpk_application_install (priv);
-out:
- g_free (package_id);
}
static gboolean
gpk_application_group_row_separator_func (GtkTreeModel *model, GtkTreeIter *iter, GpkApplicationPrivate
*priv)
{
- gchar *name = NULL;
- gboolean ret;
+ g_autofree gchar *name = NULL;
gtk_tree_model_get (model, iter, GROUPS_COLUMN_ID, &name, -1);
- ret = g_strcmp0 (name, "separator") == 0;
- g_free (name);
- return ret;
+ return g_strcmp0 (name, "separator") == 0;
}
static void
@@ -2529,7 +2380,7 @@ gpk_application_create_group_array_enum (GpkApplicationPrivate *priv)
/* create group tree view if we can search by group */
if (pk_bitfield_contain (priv->roles, PK_ROLE_ENUM_SEARCH_GROUP)) {
/* add all the groups supported (except collections, which we handled above */
- for (i=0; i<PK_GROUP_ENUM_LAST; i++) {
+ for (i = 0; i < PK_GROUP_ENUM_LAST; i++) {
if (pk_bitfield_contain (priv->groups, i) &&
i != PK_GROUP_ENUM_COLLECTIONS && i != PK_GROUP_ENUM_NEWEST)
gpk_application_group_add_data (priv, i);
@@ -2540,10 +2391,10 @@ gpk_application_create_group_array_enum (GpkApplicationPrivate *priv)
static void
gpk_application_get_categories_cb (PkClient *client, GAsyncResult *res, GpkApplicationPrivate *priv)
{
- PkResults *results;
- GError *error = NULL;
- PkError *error_code = NULL;
- GPtrArray *array = NULL;
+ g_autoptr(PkResults) results = NULL;
+ g_autoptr(GError) error = NULL;
+ g_autoptr(PkError) error_code = NULL;
+ g_autoptr(GPtrArray) array = NULL;
GtkTreeIter iter;
GtkTreeIter iter2;
guint i, j;
@@ -2551,23 +2402,12 @@ gpk_application_get_categories_cb (PkClient *client, GAsyncResult *res, GpkAppli
PkCategory *item;
PkCategory *item2;
GtkWindow *window;
- gchar *package_id = NULL;
- gchar *name = NULL;
- gchar *summary = NULL;
- gchar *cat_id = NULL;
- gchar *icon = NULL;
- gchar *parent_id_tmp = NULL;
- gchar *name_tmp = NULL;
- gchar *summary_tmp = NULL;
- gchar *cat_id_tmp = NULL;
- gchar *icon_tmp = NULL;
/* get the results */
results = pk_client_generic_finish (client, res, &error);
if (results == NULL) {
g_warning ("failed to get list of categories: %s", error->message);
- g_error_free (error);
- goto out;
+ return;
}
/* check error code */
@@ -2581,7 +2421,7 @@ gpk_application_get_categories_cb (PkClient *client, GAsyncResult *res, GpkAppli
gpk_error_dialog_modal (window, gpk_error_enum_to_localised_text (pk_error_get_code
(error_code)),
gpk_error_enum_to_localised_message (pk_error_get_code
(error_code)), pk_error_get_details (error_code));
}
- goto out;
+ return;
}
/* set to expanders with indent */
@@ -2591,7 +2431,13 @@ gpk_application_get_categories_cb (PkClient *client, GAsyncResult *res, GpkAppli
/* add repos with descriptions */
array = pk_results_get_category_array (results);
- for (i=0; i<array->len; i++) {
+ for (i = 0; i < array->len; i++) {
+ g_autofree gchar *package_id = NULL;
+ g_autofree gchar *name = NULL;
+ g_autofree gchar *summary = NULL;
+ g_autofree gchar *cat_id = NULL;
+ g_autofree gchar *icon = NULL;
+
item = g_ptr_array_index (array, i);
g_object_get (item,
"name", &name,
@@ -2610,6 +2456,12 @@ gpk_application_get_categories_cb (PkClient *client, GAsyncResult *res, GpkAppli
-1);
j = 0;
do {
+ g_autofree gchar *cat_id_tmp = NULL;
+ g_autofree gchar *icon_tmp = NULL;
+ g_autofree gchar *name_tmp = NULL;
+ g_autofree gchar *parent_id_tmp = NULL;
+ g_autofree gchar *summary_tmp = NULL;
+
/* only allows groups two layers deep */
item2 = g_ptr_array_index (array, j);
g_object_get (item2,
@@ -2631,29 +2483,11 @@ gpk_application_get_categories_cb (PkClient *client, GAsyncResult *res, GpkAppli
g_ptr_array_remove (array, item2);
} else
j++;
- g_free (parent_id_tmp);
- g_free (name_tmp);
- g_free (summary_tmp);
- g_free (cat_id_tmp);
- g_free (icon_tmp);
} while (j < array->len);
-
- g_free (package_id);
- g_free (name);
- g_free (summary);
- g_free (cat_id);
- g_free (icon);
}
/* open all expanders */
gtk_tree_view_collapse_all (treeview);
-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
@@ -2701,7 +2535,7 @@ static void
pk_backend_status_get_properties_cb (GObject *object, GAsyncResult *res, GpkApplicationPrivate *priv)
{
GtkWidget *widget;
- GError *error = NULL;
+ g_autoptr(GError) error = NULL;
PkControl *control = PK_CONTROL(object);
gboolean ret;
PkBitfield filters;
@@ -2713,8 +2547,7 @@ pk_backend_status_get_properties_cb (GObject *object, GAsyncResult *res, GpkAppl
if (!ret) {
/* TRANSLATORS: daemon is broken */
g_print ("%s: %s\n", _("Exiting as properties could not be retrieved"), error->message);
- g_error_free (error);
- goto out;
+ return;
}
/* get values */
@@ -2818,29 +2651,24 @@ pk_backend_status_get_properties_cb (GObject *object, GAsyncResult *res, GpkAppl
/* welcome */
gpk_application_add_welcome (priv);
-out:
- return;
}
static void
gpk_application_get_repo_list_cb (PkClient *client, GAsyncResult *res, GpkApplicationPrivate *priv)
{
- PkResults *results;
- GError *error = NULL;
- PkError *error_code = NULL;
- GPtrArray *array = NULL;
+ g_autoptr(PkResults) results = NULL;
+ g_autoptr(GError) error = NULL;
+ g_autoptr(PkError) error_code = NULL;
+ g_autoptr(GPtrArray) array = NULL;
PkRepoDetail *item;
guint i;
GtkWindow *window;
- gchar *repo_id = NULL;
- gchar *description = NULL;
/* get the results */
results = pk_client_generic_finish (client, res, &error);
if (results == NULL) {
g_warning ("failed to get list of repos: %s", error->message);
- g_error_free (error);
- goto out;
+ return;
}
/* check error code */
@@ -2854,12 +2682,14 @@ gpk_application_get_repo_list_cb (PkClient *client, GAsyncResult *res, GpkApplic
gpk_error_dialog_modal (window, gpk_error_enum_to_localised_text (pk_error_get_code
(error_code)),
gpk_error_enum_to_localised_message (pk_error_get_code
(error_code)), pk_error_get_details (error_code));
}
- goto out;
+ return;
}
/* add repos with descriptions */
array = pk_results_get_repo_detail_array (results);
- for (i=0; i<array->len; i++) {
+ for (i = 0; i < array->len; i++) {
+ g_autofree gchar *repo_id = NULL;
+ g_autofree gchar *description = NULL;
item = g_ptr_array_index (array, i);
g_object_get (item,
"repo-id", &repo_id,
@@ -2870,17 +2700,7 @@ gpk_application_get_repo_list_cb (PkClient *client, GAsyncResult *res, GpkApplic
/* no problem, just no point adding as we will fallback to the repo_id */
if (description != NULL)
g_hash_table_insert (priv->repos, g_strdup (repo_id), g_strdup (description));
- g_free (repo_id);
- g_free (description);
}
-
-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
@@ -2895,7 +2715,7 @@ static void
gpk_application_startup_cb (GtkApplication *application, GpkApplicationPrivate *priv)
{
GAction *action;
- GError *error = NULL;
+ g_autoptr(GError) error = NULL;
GMenuModel *menu;
GtkStyleContext *context;
GtkTreeSelection *selection;
@@ -2951,7 +2771,6 @@ gpk_application_startup_cb (GtkApplication *application, GpkApplicationPrivate *
retval = gtk_builder_add_from_file (priv->builder, GPK_DATA "/gpk-application.ui", &error);
if (retval == 0) {
g_warning ("failed to load ui: %s", error->message);
- g_error_free (error);
return;
}
@@ -3116,17 +2935,14 @@ gpk_application_activate_updates_cb (GSimpleAction *action,
gpointer user_data)
{
gboolean ret;
- gchar *command;
- GError *error = NULL;
+ g_autofree gchar *command = NULL;
+ g_autoptr(GError) error = NULL;
command = g_build_filename (BINDIR, "gpk-update-viewer", NULL);
g_debug ("running: %s", command);
ret = g_spawn_command_line_async (command, &error);
- if (!ret) {
+ if (!ret)
g_warning ("spawn of %s failed: %s", command, error->message);
- g_error_free (error);
- }
- g_free (command);
}
@@ -3146,7 +2962,7 @@ main (int argc, char *argv[])
GOptionContext *context;
gboolean ret;
gint status = 0;
- gchar *filename;
+ g_autofree gchar *filename = NULL;
GpkApplicationPrivate *priv;
const GOptionEntry options[] = {
@@ -3203,7 +3019,6 @@ main (int argc, char *argv[])
GAction *action = g_action_map_lookup_action (G_ACTION_MAP (priv->application), "updates");
g_simple_action_set_enabled (G_SIMPLE_ACTION (action), FALSE);
}
- g_free (filename);
/* run */
status = g_application_run (G_APPLICATION (priv->application), argc, argv);
diff --git a/src/gpk-cell-renderer-info.c b/src/gpk-cell-renderer-info.c
index c6d5998..f7ea25c 100644
--- a/src/gpk-cell-renderer-info.c
+++ b/src/gpk-cell-renderer-info.c
@@ -68,20 +68,17 @@ static gboolean
gpk_cell_renderer_should_show (GpkCellRendererInfo *cru)
{
guint i;
- gboolean ret = FALSE;
GPtrArray *array;
PkInfoEnum info;
/* are we in the ignore array */
array = cru->priv->ignore;
- for (i=0; i<array->len; i++) {
+ for (i = 0; i < array->len; i++) {
info = GPOINTER_TO_UINT (g_ptr_array_index (array, i));
if (info == cru->priv->value)
- goto out;
+ return FALSE;
}
- ret = TRUE;
-out:
- return ret;
+ return TRUE;
}
static void
@@ -89,7 +86,7 @@ gpk_cell_renderer_info_set_property (GObject *object, guint param_id,
const GValue *value, GParamSpec *pspec)
{
const gchar *text;
- gchar **split;
+ g_auto(GStrv) split = NULL;
gboolean ret;
guint i;
PkInfoEnum info;
@@ -114,7 +111,6 @@ gpk_cell_renderer_info_set_property (GObject *object, guint param_id,
info = pk_info_enum_from_string (split[i]);
g_ptr_array_add (cru->priv->ignore, GUINT_TO_POINTER (info));
}
- g_strfreev (split);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
diff --git a/src/gpk-common.c b/src/gpk-common.c
index 828164f..287f2a2 100644
--- a/src/gpk-common.c
+++ b/src/gpk-common.c
@@ -67,7 +67,7 @@ pk_strv_to_ptr_array (gchar **array)
parray = g_ptr_array_new ();
length = g_strv_length (array);
- for (i=0; i<length; i++)
+ for (i = 0; i < length; i++)
g_ptr_array_add (parray, g_strdup (array[i]));
return parray;
}
@@ -162,11 +162,10 @@ gpk_package_id_format_twoline (GtkStyleContext *style,
const gchar *package_id,
const gchar *summary)
{
- gchar *summary_safe = NULL;
- gchar *text = NULL;
+ g_autofree gchar *summary_safe = NULL;
GString *string;
- gchar **split = NULL;
- gchar *color;
+ g_auto(GStrv) split = NULL;
+ g_autofree gchar *color = NULL;
const gchar *arch;
GdkRGBA inactive;
@@ -189,7 +188,7 @@ gpk_package_id_format_twoline (GtkStyleContext *style,
split = pk_package_id_split (package_id);
if (split == NULL) {
g_warning ("could not parse %s", package_id);
- goto out;
+ return NULL;
}
/* no summary */
@@ -200,8 +199,7 @@ gpk_package_id_format_twoline (GtkStyleContext *style,
arch = gpk_get_pretty_arch (split[PK_PACKAGE_ID_ARCH]);
if (arch != NULL)
g_string_append_printf (string, " (%s)", arch);
- text = g_string_free (string, FALSE);
- goto out;
+ return g_string_free (string, FALSE);
}
/* name and summary */
@@ -216,50 +214,39 @@ gpk_package_id_format_twoline (GtkStyleContext *style,
if (arch != NULL)
g_string_append_printf (string, " (%s)", arch);
g_string_append (string, "</span>");
- text = g_string_free (string, FALSE);
-out:
- g_free (summary_safe);
- g_free (color);
- g_strfreev (split);
- return text;
+ return g_string_free (string, FALSE);
}
gchar *
gpk_package_id_format_oneline (const gchar *package_id, const gchar *summary)
{
- gchar *summary_safe;
- gchar *text;
- gchar **split;
+ g_autofree gchar *summary_safe = NULL;
+ g_auto(GStrv) split = NULL;
g_return_val_if_fail (package_id != NULL, NULL);
split = pk_package_id_split (package_id);
if (summary == NULL || summary[0] == '\0') {
/* just have name */
- text = g_strdup (split[PK_PACKAGE_ID_NAME]);
- } else {
- summary_safe = g_markup_escape_text (summary, -1);
- text = g_strdup_printf ("<b>%s</b> (%s)", summary_safe, split[PK_PACKAGE_ID_NAME]);
- g_free (summary_safe);
+ return g_strdup (split[PK_PACKAGE_ID_NAME]);
}
- g_strfreev (split);
- return text;
+ summary_safe = g_markup_escape_text (summary, -1);
+ return g_strdup_printf ("<b>%s</b> (%s)", summary_safe, split[PK_PACKAGE_ID_NAME]);
}
gboolean
gpk_check_privileged_user (const gchar *application_name, gboolean show_ui)
{
guint uid;
- gboolean ret = TRUE;
- gchar *message = NULL;
- gchar *title = NULL;
+ g_autofree gchar *message = NULL;
+ g_autofree gchar *title = NULL;
GtkResponseType result;
GtkWidget *dialog;
uid = getuid ();
if (uid == 0) {
if (!show_ui)
- goto out;
+ return TRUE;
if (application_name == NULL)
/* TRANSLATORS: these tools cannot run as root (unknown name) */
title = g_strdup (_("This application is running as a privileged user"));
@@ -284,15 +271,11 @@ gpk_check_privileged_user (const gchar *application_name, gboolean show_ui)
/* user did not agree to run insecure */
if (result != GTK_RESPONSE_OK) {
- ret = FALSE;
g_warning ("uid=%i so closing", uid);
- goto out;
+ return FALSE;
}
}
-out:
- g_free (title);
- g_free (message);
- return ret;
+ return TRUE;
}
/**
diff --git a/src/gpk-dialog.c b/src/gpk-dialog.c
index dc97320..e3e772c 100644
--- a/src/gpk-dialog.c
+++ b/src/gpk-dialog.c
@@ -43,29 +43,26 @@ gpk_dialog_package_id_name_join_locale (gchar **package_ids)
guint i;
guint length;
gchar *text;
- GPtrArray *array;
- gchar **array_strv;
- gchar **split;
+ g_autoptr(GPtrArray) array = NULL;
+ g_auto(GStrv) array_strv = NULL;
length = g_strv_length (package_ids);
array = g_ptr_array_new_with_free_func (g_free);
- for (i=0; i<length; i++) {
+ for (i = 0; i < length; i++) {
+ g_auto(GStrv) split = NULL;
split = pk_package_id_split (package_ids[i]);
if (split == NULL) {
g_warning ("failed to split %s", package_ids[i]);
continue;
}
g_ptr_array_add (array, g_strdup (split[0]));
- g_strfreev (split);
}
array_strv = pk_ptr_array_to_strv (array);
text = gpk_strv_join_locale (array_strv);
- g_strfreev (array_strv);
if (text == NULL) {
/* TRANSLATORS: This is when we have over 5 items, and we're not interested in detail */
text = g_strdup (_("many packages"));
}
- g_ptr_array_unref (array);
return text;
}
@@ -76,17 +73,17 @@ gpk_dialog_package_array_to_list_store (GPtrArray *array)
GtkTreeIter iter;
PkPackage *item;
const gchar *icon;
- gchar *text;
guint i;
- gchar **split;
PkInfoEnum info;
- gchar *package_id = NULL;
- gchar *summary = NULL;
store = gtk_list_store_new (GPK_DIALOG_STORE_LAST, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);
/* add each well */
- for (i=0; i<array->len; i++) {
+ for (i = 0; i < array->len; i++) {
+ g_auto(GStrv) split = NULL;
+ g_autofree gchar *text = NULL;
+ g_autofree gchar *package_id = NULL;
+ g_autofree gchar *summary = NULL;
item = g_ptr_array_index (array, i);
g_object_get (item,
"info", &info,
@@ -105,10 +102,6 @@ gpk_dialog_package_array_to_list_store (GPtrArray *array)
GPK_DIALOG_STORE_ID, package_id,
GPK_DIALOG_STORE_TEXT, text,
-1);
- g_strfreev (split);
- g_free (package_id);
- g_free (summary);
- g_free (text);
}
return store;
@@ -203,8 +196,8 @@ gpk_dialog_embed_file_list_widget (GtkDialog *dialog, GPtrArray *files)
GtkWidget *scroll;
GtkWidget *widget;
GtkTextBuffer *buffer;
- gchar **array;
- gchar *text;
+ g_auto(GStrv) array = NULL;
+ g_autofree gchar *text = NULL;
/* split and show */
array = pk_ptr_array_to_strv (files);
@@ -240,7 +233,6 @@ gpk_dialog_embed_file_list_widget (GtkDialog *dialog, GPtrArray *files)
/* add scrolled window */
widget = gtk_dialog_get_content_area (GTK_DIALOG(dialog));
gtk_box_pack_start (GTK_BOX (widget), scroll, TRUE, TRUE, 0);
- g_free (text);
return TRUE;
}
@@ -249,14 +241,13 @@ static void
gpk_client_checkbutton_show_depends_cb (GtkWidget *widget, const gchar *key)
{
gboolean checked;
- GSettings *settings;
+ g_autoptr(GSettings) settings = NULL;
/* set the policy */
checked = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget));
g_debug ("Changing %s to %i", key, checked);
settings = g_settings_new (GPK_SETTINGS_SCHEMA);
g_settings_set_boolean (settings, key, !checked);
- g_object_unref (settings);
}
gboolean
@@ -265,7 +256,7 @@ gpk_dialog_embed_do_not_show_widget (GtkDialog *dialog, const gchar *key)
GtkWidget *check_button;
GtkWidget *widget;
gboolean checked;
- GSettings *settings;
+ g_autoptr(GSettings) settings = NULL;
/* add a checkbutton for deps screen */
check_button = gtk_check_button_new_with_label (_("Do not show this again"));
@@ -279,7 +270,6 @@ gpk_dialog_embed_do_not_show_widget (GtkDialog *dialog, const gchar *key)
/* checked? */
settings = g_settings_new (GPK_SETTINGS_SCHEMA);
checked = g_settings_get_boolean (settings, key);
- g_object_unref (settings);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check_button), !checked);
gtk_widget_show (check_button);
@@ -354,8 +344,8 @@ gpk_dialog_tabbed_download_size_widget (GtkWidget *tab_page, const gchar *title,
{
GtkWidget *label;
GtkWidget *hbox;
- gchar *text = NULL;
- gchar *size_str = NULL;
+ g_autofree gchar *text = NULL;
+ g_autofree gchar *size_str = NULL;
/* size is zero, don't show "0 bytes" */
if (size == 0) {
@@ -382,7 +372,5 @@ gpk_dialog_tabbed_download_size_widget (GtkWidget *tab_page, const gchar *title,
gtk_widget_show (hbox);
out:
gtk_widget_show (label);
- g_free (text);
- g_free (size_str);
return TRUE;
}
diff --git a/src/gpk-error.c b/src/gpk-error.c
index 2da6059..b9dd1ec 100644
--- a/src/gpk-error.c
+++ b/src/gpk-error.c
@@ -59,10 +59,10 @@ static gboolean
gpk_error_dialog_modal_with_time (GtkWindow *window, const gchar *title, const gchar *message, const gchar
*details, guint timestamp)
{
GtkWidget *widget;
- GtkBuilder *builder;
- GtkTextBuffer *buffer = NULL;
+ g_autoptr(GtkBuilder) builder = NULL;
+ g_autoptr(GtkTextBuffer) buffer = NULL;
guint retval;
- GError *error = NULL;
+ g_autoptr(GError) error = NULL;
g_return_val_if_fail (message != NULL, FALSE);
@@ -71,8 +71,7 @@ gpk_error_dialog_modal_with_time (GtkWindow *window, const gchar *title, const g
retval = gtk_builder_add_from_file (builder, GPK_DATA "/gpk-error.ui", &error);
if (retval == 0) {
g_warning ("failed to load ui: %s", error->message);
- g_error_free (error);
- goto out_build;
+ return FALSE;
}
/* connect up actions */
@@ -131,10 +130,6 @@ gpk_error_dialog_modal_with_time (GtkWindow *window, const gchar *title, const g
/* hide window */
if (GTK_IS_WIDGET (widget))
gtk_widget_hide (widget);
- if (buffer != NULL)
- g_object_unref (buffer);
-out_build:
- g_object_unref (builder);
return TRUE;
}
diff --git a/src/gpk-log.c b/src/gpk-log.c
index fb01ad6..3755c08 100644
--- a/src/gpk-log.c
+++ b/src/gpk-log.c
@@ -151,24 +151,23 @@ gpk_log_get_type_line (gchar **array, PkInfoEnum info)
PkInfoEnum info_local;
const gchar *info_text;
GString *string;
- gchar *text;
+ g_autofree gchar *text = NULL;
gchar *whole;
- gchar **sections;
string = g_string_new ("");
size = g_strv_length (array);
info_text = gpk_info_enum_to_localised_past (info);
/* find all of this type */
- for (i=0; i<size; i++) {
+ for (i = 0; i < size; i++) {
+ g_auto(GStrv) sections = NULL;
sections = g_strsplit (array[i], "\t", 0);
info_local = pk_info_enum_from_string (sections[0]);
if (info_local == info) {
- text = gpk_package_id_format_oneline (sections[1], NULL);
- g_string_append_printf (string, "%s, ", text);
- g_free (text);
+ g_autofree gchar *str = NULL;
+ str = gpk_package_id_format_oneline (sections[1], NULL);
+ g_string_append_printf (string, "%s, ", str);
}
- g_strfreev (sections);
}
/* nothing, so return NULL */
@@ -183,7 +182,6 @@ gpk_log_get_type_line (gchar **array, PkInfoEnum info)
/* add a nice header, and make text italic */
text = g_string_free (string, FALSE);
whole = g_strdup_printf ("<b>%s</b>: %s\n", info_text, text);
- g_free (text);
return whole;
}
@@ -192,7 +190,7 @@ gpk_log_get_details_localised (const gchar *timespec, const gchar *data)
{
GString *string;
gchar *text;
- gchar **array;
+ g_auto(GStrv) array = NULL;
string = g_string_new ("");
array = g_strsplit (data, "\n", 0);
@@ -210,7 +208,6 @@ gpk_log_get_details_localised (const gchar *timespec, const gchar *data)
if (text != NULL)
g_string_append (string, text);
g_free (text);
- g_strfreev (array);
/* remove last \n */
if (string->len > 0)
@@ -322,13 +319,11 @@ gpk_log_filter (PkTransactionPast *item)
gboolean ret = FALSE;
guint i;
guint length;
- gchar **sections;
- gchar **packages;
- gchar **split;
- gchar *tid;
+ g_auto(GStrv) packages = NULL;
+ g_autofree gchar *tid = NULL;
gboolean succeeded;
- gchar *cmdline;
- gchar *data;
+ g_autofree gchar *cmdline = NULL;
+ g_autofree gchar *data = NULL;
/* get data */
g_object_get (item,
@@ -354,7 +349,9 @@ gpk_log_filter (PkTransactionPast *item)
/* look in all the data for the filter string */
packages = g_strsplit (data, "\n", 0);
length = g_strv_length (packages);
- for (i=0; i<length; i++) {
+ for (i = 0; i < length; i++) {
+ g_auto(GStrv) split = NULL;
+ g_auto(GStrv) sections = NULL;
sections = g_strsplit (packages[i], "\t", 0);
/* check if type matches filter */
@@ -370,19 +367,10 @@ gpk_log_filter (PkTransactionPast *item)
if (split[2] != NULL && g_strrstr (split[2], filter) != NULL)
ret = TRUE;
- g_strfreev (split);
- g_strfreev (sections);
-
/* shortcut for speed */
if (ret)
break;
}
-
- g_free (tid);
- g_free (cmdline);
- g_free (data);
- g_strfreev (packages);
-
return ret;
}
@@ -390,21 +378,21 @@ static void
gpk_log_add_item (PkTransactionPast *item)
{
GtkTreeIter iter;
- gchar *details;
- gchar *date;
+ g_autofree gchar *details = NULL;
+ g_autofree gchar *date = NULL;
const gchar *icon_name;
const gchar *role_text;
const gchar *username = NULL;
const gchar *tool;
static guint count;
struct passwd *pw;
- gchar *tid;
- gchar *timespec;
+ g_autofree gchar *tid = NULL;
+ g_autofree gchar *timespec = NULL;
gboolean succeeded;
guint duration;
- gchar *cmdline;
+ g_autofree gchar *cmdline = NULL;
guint uid;
- gchar *data;
+ g_autofree gchar *data = NULL;
PkRoleEnum role;
GtkTreeView *treeview = GTK_TREE_VIEW (gtk_builder_get_object (builder, "treeview_simple"));
GtkTreeModel *model = gtk_tree_view_get_model (treeview);
@@ -479,13 +467,6 @@ gpk_log_add_item (PkTransactionPast *item)
if (count++ % 10 == 0)
while (gtk_events_pending ())
gtk_main_iteration ();
-
- g_free (tid);
- g_free (timespec);
- g_free (cmdline);
- g_free (data);
- g_free (details);
- g_free (date);
}
static void
@@ -516,7 +497,7 @@ gpk_log_refilter (void)
gpk_log_mark_nonactive (model);
/* go through the list, adding and removing the items as required */
- for (i=0; i<transactions->len; i++) {
+ for (i = 0; i < transactions->len; i++) {
item = g_ptr_array_index (transactions, i);
ret = gpk_log_filter (item);
if (ret)
@@ -531,23 +512,22 @@ static void
gpk_log_get_old_transactions_cb (GObject *object, GAsyncResult *res, gpointer user_data)
{
// PkClient *client = PK_CLIENT (object);
- GError *error = NULL;
+ g_autoptr(GError) error = NULL;
PkResults *results = NULL;
- PkError *error_code = NULL;
+ g_autoptr(PkError) error_code = NULL;
/* get the results */
results = pk_client_generic_finish (client, res, &error);
if (results == NULL) {
g_warning ("failed to get old transactions: %s", error->message);
- g_error_free (error);
- goto out;
+ return;
}
/* check error code */
error_code = pk_results_get_error_code (results);
if (error_code != NULL) {
g_warning ("failed to get old transactions: %s, %s", pk_error_enum_to_string
(pk_error_get_code (error_code)), pk_error_get_details (error_code));
- goto out;
+ return;
}
/* get the list */
@@ -555,11 +535,6 @@ gpk_log_get_old_transactions_cb (GObject *object, GAsyncResult *res, gpointer us
g_ptr_array_unref (transactions);
transactions = pk_results_get_transaction_array (results);
gpk_log_refilter ();
-out:
- if (error_code != NULL)
- g_object_unref (error_code);
- if (results != NULL)
- g_object_unref (results);
}
static void
@@ -607,7 +582,7 @@ gpk_log_activate_cb (GtkApplication *application, gpointer user_data)
static void
gpk_log_startup_cb (GtkApplication *application, gpointer user_data)
{
- GError *error = NULL;
+ g_autoptr(GError) error = NULL;
GtkTreeSelection *selection;
GtkWidget *widget;
GtkWindow *window;
@@ -623,7 +598,6 @@ gpk_log_startup_cb (GtkApplication *application, gpointer user_data)
retval = gtk_builder_add_from_file (builder, GPK_DATA "/gpk-log.ui", &error);
if (retval == 0) {
g_warning ("failed to load ui: %s", error->message);
- g_error_free (error);
goto out;
}
@@ -706,7 +680,7 @@ main (int argc, char *argv[])
gboolean ret;
gint status = 1;
GOptionContext *context;
- GtkApplication *application = NULL;
+ g_autoptr(GtkApplication) application = NULL;
const GOptionEntry options[] = {
{ "filter", 'f', 0, G_OPTION_ARG_STRING, &filter,
@@ -755,7 +729,5 @@ main (int argc, char *argv[])
out:
if (builder != NULL)
g_object_unref (builder);
- if (application != NULL)
- g_object_unref (application);
return status;
}
diff --git a/src/gpk-prefs.c b/src/gpk-prefs.c
index 04595e2..f0b8ac1 100644
--- a/src/gpk-prefs.c
+++ b/src/gpk-prefs.c
@@ -167,35 +167,32 @@ gpk_prefs_progress_cb (PkProgress *progress, PkProgressType type, GpkPrefsPrivat
gtk_widget_hide (widget);
widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "scrolledwindow_repo"));
gtk_widget_show (widget);
- goto out;
+ return;
}
/* already pending show */
if (priv->status_id > 0)
- goto out;
+ return;
/* only show after some time in the transaction */
priv->status_id = g_timeout_add (GPK_UI_STATUS_SHOW_DELAY, (GSourceFunc)
gpk_prefs_status_changed_timeout_cb, priv);
g_source_set_name_by_id (priv->status_id, "[GpkRepo] status");
-out:
- return;
}
static void
gpk_prefs_repo_enable_cb (GObject *object, GAsyncResult *res, GpkPrefsPrivate *priv)
{
- GError *error = NULL;
+ g_autoptr(GError) error = NULL;
GtkWindow *window;
PkClient *client = PK_CLIENT (object);
- PkError *error_code = NULL;
+ g_autoptr(PkError) error_code = NULL;
PkResults *results = NULL;
/* get the results */
results = pk_client_generic_finish (client, res, &error);
if (results == NULL) {
g_warning ("failed to get set repo: %s", error->message);
- g_error_free (error);
- goto out;
+ return;
}
/* check error code */
@@ -206,29 +203,24 @@ gpk_prefs_repo_enable_cb (GObject *object, GAsyncResult *res, GpkPrefsPrivate *p
/* TRANSLATORS: for one reason or another, we could not enable or disable a package source */
gpk_error_dialog_modal (window, _("Failed to change status"),
gpk_error_enum_to_localised_text (pk_error_get_code (error_code)),
pk_error_get_details (error_code));
- goto out;
+ return;
}
-out:
- if (error_code != NULL)
- g_object_unref (error_code);
- if (results != NULL)
- g_object_unref (results);
}
static void
gpk_misc_enabled_toggled (GtkCellRendererToggle *cell, gchar *path_str, GpkPrefsPrivate *priv)
{
gboolean enabled;
- gchar *repo_id = NULL;
+ g_autofree gchar *repo_id = NULL;
GtkTreeIter iter;
GtkTreeModel *model;
- GtkTreePath *path = gtk_tree_path_new_from_string (path_str);
+ g_autofree GtkTreePath *path = gtk_tree_path_new_from_string (path_str);
GtkTreeView *treeview;
/* do we have the capability? */
if (pk_bitfield_contain (priv->roles, PK_ROLE_ENUM_REPO_ENABLE) == FALSE) {
g_debug ("can't change state");
- goto out;
+ return;
}
/* get toggled iter */
@@ -254,10 +246,6 @@ gpk_misc_enabled_toggled (GtkCellRendererToggle *cell, gchar *path_str, GpkPrefs
(PkProgressCallback) gpk_prefs_progress_cb, priv,
(GAsyncReadyCallback) gpk_prefs_repo_enable_cb, priv);
-out:
- /* clean up */
- g_free (repo_id);
- gtk_tree_path_free (path);
}
static void
@@ -308,17 +296,15 @@ static void
gpk_prefs_get_repo_list_cb (GObject *object, GAsyncResult *res, GpkPrefsPrivate *priv)
{
gboolean enabled;
- gchar *description;
- gchar *repo_id;
- GError *error = NULL;
- GPtrArray *array = NULL;
+ g_autoptr(GError) error = NULL;
+ g_autoptr(GPtrArray) array = NULL;
GtkTreeIter iter;
GtkTreeModel *model;
GtkTreeView *treeview;
GtkWindow *window;
guint i;
PkClient *client = PK_CLIENT (object);
- PkError *error_code = NULL;
+ g_autoptr(PkError) error_code = NULL;
PkRepoDetail *item;
PkResults *results = NULL;
@@ -326,8 +312,7 @@ gpk_prefs_get_repo_list_cb (GObject *object, GAsyncResult *res, GpkPrefsPrivate
results = pk_client_generic_finish (client, res, &error);
if (results == NULL) {
g_warning ("failed to get repo list: %s", error->message);
- g_error_free (error);
- goto out;
+ return;
}
/* check error code */
@@ -338,14 +323,16 @@ gpk_prefs_get_repo_list_cb (GObject *object, GAsyncResult *res, GpkPrefsPrivate
/* TRANSLATORS: for one reason or another, we could not get the list of sources */
gpk_error_dialog_modal (window, _("Failed to get the list of sources"),
gpk_error_enum_to_localised_text (pk_error_get_code (error_code)),
pk_error_get_details (error_code));
- goto out;
+ return;
}
/* add repos */
treeview = GTK_TREE_VIEW (gtk_builder_get_object (priv->builder, "treeview_repo"));
model = gtk_tree_view_get_model (treeview);
array = pk_results_get_repo_detail_array (results);
- for (i=0; i<array->len; i++) {
+ for (i = 0; i < array->len; i++) {
+ g_autofree gchar *description = NULL;
+ g_autofree gchar *repo_id = NULL;
item = g_ptr_array_index (array, i);
g_object_get (item,
"repo-id", &repo_id,
@@ -361,9 +348,6 @@ gpk_prefs_get_repo_list_cb (GObject *object, GAsyncResult *res, GpkPrefsPrivate
GPK_COLUMN_ACTIVE, TRUE,
GPK_COLUMN_SENSITIVE, TRUE,
-1);
-
- g_free (repo_id);
- g_free (description);
}
/* remove the items that are not now present */
@@ -371,13 +355,6 @@ gpk_prefs_get_repo_list_cb (GObject *object, GAsyncResult *res, GpkPrefsPrivate
/* sort */
gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE(priv->list_store), GPK_COLUMN_TEXT,
GTK_SORT_ASCENDING);
-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
@@ -423,7 +400,7 @@ static void
gpk_prefs_get_properties_cb (GObject *object, GAsyncResult *res, GpkPrefsPrivate *priv)
{
gboolean ret;
- GError *error = NULL;
+ g_autoptr(GError) error = NULL;
GtkWidget *widget;
PkControl *control = PK_CONTROL(object);
@@ -432,8 +409,7 @@ gpk_prefs_get_properties_cb (GObject *object, GAsyncResult *res, GpkPrefsPrivate
if (!ret) {
/* TRANSLATORS: backend is broken, and won't tell us what it supports */
g_print ("%s: %s\n", _("Exiting as backend details could not be retrieved"), error->message);
- g_error_free (error);
- goto out;
+ return;
}
/* get values */
@@ -462,8 +438,6 @@ gpk_prefs_get_properties_cb (GObject *object, GAsyncResult *res, GpkPrefsPrivate
widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "checkbutton_detail"));
gtk_widget_set_sensitive (widget, FALSE);
}
-out:
- return;
}
static void
@@ -476,12 +450,12 @@ gpk_prefs_close_cb (GtkWidget *widget, gpointer data)
static void
gpk_pack_startup_cb (GtkApplication *application, GpkPrefsPrivate *priv)
{
- GError *error = NULL;
+ g_autoptr(GError) error = NULL;
GtkTreeSelection *selection;
GtkWidget *main_window;
GtkWidget *widget;
guint retval;
- PkControl *control;
+ g_autoptr(PkControl) control = NULL;
/* add application specific icons to search path */
gtk_icon_theme_append_search_path (gtk_icon_theme_get_default (),
@@ -496,8 +470,7 @@ gpk_pack_startup_cb (GtkApplication *application, GpkPrefsPrivate *priv)
retval = gtk_builder_add_from_file (priv->builder, GPK_DATA "/gpk-prefs.ui", &error);
if (retval == 0) {
g_warning ("failed to load ui: %s", error->message);
- g_error_free (error);
- goto out;
+ return;
}
widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "button_close"));
@@ -532,8 +505,6 @@ gpk_pack_startup_cb (GtkApplication *application, GpkPrefsPrivate *priv)
/* get some data */
pk_control_get_properties_async (control, NULL, (GAsyncReadyCallback) gpk_prefs_get_properties_cb,
priv);
-out:
- g_object_unref (control);
}
@@ -542,10 +513,9 @@ gpm_prefs_commandline_cb (GApplication *application,
GApplicationCommandLine *cmdline,
GpkPrefsPrivate *priv)
{
- gboolean ret;
- gchar **argv;
+ g_auto(GStrv) argv = NULL;
gint argc;
- GOptionContext *context;
+ g_autoptr(GOptionContext) context = NULL;
GtkWindow *window;
guint xid = 0;
@@ -564,9 +534,8 @@ gpm_prefs_commandline_cb (GApplication *application,
g_option_context_set_summary(context, _("Package Sources"));
g_option_context_add_main_entries (context, options, NULL);
g_option_context_add_group (context, gpk_debug_get_option_group ());
- ret = g_option_context_parse (context, &argc, &argv, NULL);
- if (!ret)
- goto out;
+ if (!g_option_context_parse (context, &argc, &argv, NULL))
+ return FALSE;
/* make sure the window is raised */
window = GTK_WINDOW (gtk_builder_get_object (priv->builder, "dialog_prefs"));
@@ -577,10 +546,7 @@ gpm_prefs_commandline_cb (GApplication *application,
g_debug ("Setting xid %i", xid);
gpk_window_set_parent_xid (window, xid);
}
-out:
- g_strfreev (argv);
- g_option_context_free (context);
- return ret;
+ return TRUE;
}
int
diff --git a/src/gpk-self-test.c b/src/gpk-self-test.c
index d26dcc5..f513ab9 100644
--- a/src/gpk-self-test.c
+++ b/src/gpk-self-test.c
@@ -279,16 +279,15 @@ static void
gpk_task_test_install_packages_cb (GObject *object, GAsyncResult *res, gpointer user_data)
{
GpkTask *task = GPK_TASK (object);
- GError *error = NULL;
- PkResults *results;
- GPtrArray *packages;
- PkError *error_code = NULL;
+ g_autoptr(GError) error = NULL;
+ g_autoptr(PkResults) results = NULL;
+ g_autoptr(GPtrArray) packages = NULL;
+ g_autoptr(PkError) error_code = NULL;
/* get the results */
results = pk_task_generic_finish (PK_TASK(task), res, &error);
if (results == NULL) {
g_warning ("failed to resolve: %s", error->message);
- g_error_free (error);
goto out;
}
@@ -303,13 +302,7 @@ gpk_task_test_install_packages_cb (GObject *object, GAsyncResult *res, gpointer
if (packages->len != 4)
g_warning ("invalid number of packages: %i", packages->len);
-
- g_ptr_array_unref (packages);
out:
- if (error_code != NULL)
- g_object_unref (error_code);
- if (results != NULL)
- g_object_unref (results);
_g_test_loop_quit ();
}
@@ -328,8 +321,8 @@ gpk_task_test_progress_cb (PkProgress *progress, PkProgressType type, gpointer u
static void
gpk_test_task_func (void)
{
- GpkTask *task;
- gchar **package_ids;
+ g_autoptr(GpkTask) task = NULL;
+ g_auto(GStrv) package_ids = NULL;
/* get task */
task = gpk_task_new ();
@@ -346,10 +339,7 @@ gpk_test_task_func (void)
pk_task_install_packages_async (PK_TASK(task), package_ids, NULL,
(PkProgressCallback) gpk_task_test_progress_cb, NULL,
(GAsyncReadyCallback) gpk_task_test_install_packages_cb, NULL);
- g_strfreev (package_ids);
_g_test_loop_wait (150000);
-
- g_object_unref (task);
}
int
diff --git a/src/gpk-task.c b/src/gpk-task.c
index 733105e..d4245a5 100644
--- a/src/gpk-task.c
+++ b/src/gpk-task.c
@@ -90,7 +90,7 @@ static void
gpk_task_untrusted_question (PkTask *task, guint request, PkResults *results)
{
GtkWidget *widget;
- gchar *message;
+ g_autofree gchar *message = NULL;
PkRoleEnum role;
GpkTaskPrivate *priv = GPK_TASK(task)->priv;
@@ -126,7 +126,6 @@ gpk_task_untrusted_question (PkTask *task, guint request, PkResults *results)
}
widget = GTK_WIDGET (gtk_builder_get_object (priv->builder_untrusted, "label_message"));
gtk_label_set_markup (GTK_LABEL (widget), message);
- g_free (message);
/* show window */
priv->current_window = GTK_WINDOW(gtk_builder_get_object (priv->builder_untrusted, "dialog_error"));
@@ -143,14 +142,14 @@ gpk_task_untrusted_question (PkTask *task, guint request, PkResults *results)
static void
gpk_task_key_question (PkTask *task, guint request, PkResults *results)
{
- GPtrArray *array;
+ g_autoptr(GPtrArray) array = NULL;
GtkWidget *widget;
- gchar *printable = NULL;
- gchar *package_id = NULL;
- gchar *repository_name = NULL;
- gchar *key_url = NULL;
- gchar *key_userid = NULL;
- gchar *key_id = NULL;
+ g_autofree gchar *printable = NULL;
+ g_autofree gchar *package_id = NULL;
+ g_autofree gchar *repository_name = NULL;
+ g_autofree gchar *key_url = NULL;
+ g_autofree gchar *key_userid = NULL;
+ g_autofree gchar *key_id = NULL;
PkRepoSignatureRequired *item;
GpkTaskPrivate *priv = GPK_TASK(task)->priv;
@@ -161,7 +160,7 @@ gpk_task_key_question (PkTask *task, guint request, PkResults *results)
array = pk_results_get_repo_signature_required_array (results);
if (array->len != 1) {
g_warning ("array length %i, aborting", array->len);
- goto out;
+ return;
}
/* only one item supported */
@@ -198,28 +197,20 @@ gpk_task_key_question (PkTask *task, guint request, PkResults *results)
}
priv->help_id = "gpg-signature";
gtk_widget_show (GTK_WIDGET(priv->current_window));
-out:
- g_free (printable);
- g_free (package_id);
- g_free (repository_name);
- g_free (key_url);
- g_free (key_userid);
- g_free (key_id);
- g_ptr_array_unref (array);
}
static void
gpk_task_eula_question (PkTask *task, guint request, PkResults *results)
{
- GPtrArray *array;
+ g_autoptr(GPtrArray) array = NULL;
GtkWidget *widget;
- GtkTextBuffer *buffer;
- gchar *printable = NULL;
- gchar **split = NULL;
+ g_autoptr(GtkTextBuffer) buffer = NULL;
+ g_autofree gchar *printable = NULL;
+ g_auto(GStrv) split = NULL;
PkEulaRequired *item;
- gchar *package_id = NULL;
- gchar *vendor_name = NULL;
- gchar *license_agreement = NULL;
+ g_autofree gchar *package_id = NULL;
+ g_autofree gchar *vendor_name = NULL;
+ g_autofree gchar *license_agreement = NULL;
GpkTaskPrivate *priv = GPK_TASK(task)->priv;
/* save the current request */
@@ -229,7 +220,7 @@ gpk_task_eula_question (PkTask *task, guint request, PkResults *results)
array = pk_results_get_eula_required_array (results);
if (array->len != 1) {
g_warning ("array length %i, aborting", array->len);
- goto out;
+ return;
}
/* only one item supported */
@@ -265,24 +256,15 @@ gpk_task_eula_question (PkTask *task, guint request, PkResults *results)
}
priv->help_id = "eula";
gtk_widget_show (GTK_WIDGET(priv->current_window));
-
- g_object_unref (buffer);
-out:
- g_free (printable);
- g_free (package_id);
- g_free (vendor_name);
- g_free (license_agreement);
- g_strfreev (split);
- g_ptr_array_unref (array);
}
static void
gpk_task_media_change_question (PkTask *task, guint request, PkResults *results)
{
- GPtrArray *array;
+ g_autoptr(GPtrArray) array = NULL;
PkMediaChangeRequired *item;
const gchar *name;
- gchar *message = NULL;
+ g_autofree gchar *message = NULL;
gchar *media_id;
PkMediaTypeEnum media_type;
gchar *media_text;
@@ -295,7 +277,7 @@ gpk_task_media_change_question (PkTask *task, guint request, PkResults *results)
array = pk_results_get_media_change_required_array (results);
if (array->len != 1) {
g_warning ("array length %i, aborting", array->len);
- goto out;
+ return;
}
/* only one item supported */
@@ -324,9 +306,6 @@ gpk_task_media_change_question (PkTask *task, guint request, PkResults *results)
g_signal_connect (priv->current_window, "response", G_CALLBACK (gpk_task_dialog_response_cb), task);
gtk_widget_show_all (GTK_WIDGET(priv->current_window));
-out:
- g_free (message);
- g_ptr_array_unref (array);
}
static void
@@ -335,10 +314,10 @@ gpk_task_add_dialog_deps_section (PkTask *task,
PkPackageSack *sack,
PkInfoEnum info)
{
- PkPackageSack *sack_tmp;
- GPtrArray *array_tmp = NULL;
+ g_autoptr(PkPackageSack) sack_tmp = NULL;
+ g_autoptr(GPtrArray) array_tmp = NULL;
gboolean ret;
- GError *error = NULL;
+ g_autoptr(GError) error = NULL;
guint64 size;
const gchar *title;
GtkWidget *tab_page;
@@ -347,7 +326,7 @@ gpk_task_add_dialog_deps_section (PkTask *task,
sack_tmp = pk_package_sack_filter_by_info (sack, info);
if (pk_package_sack_get_size (sack_tmp) == 0) {
g_debug ("no packages with %s", pk_info_enum_to_string (info));
- goto out;
+ return;
}
tab_page = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
@@ -396,7 +375,6 @@ gpk_task_add_dialog_deps_section (PkTask *task,
ret = pk_package_sack_get_details (sack_tmp, NULL, &error);
if (!ret) {
g_warning ("failed to get details about packages: %s", error->message);
- g_error_free (error);
}
size = pk_package_sack_get_total_bytes (sack_tmp);
@@ -405,20 +383,16 @@ gpk_task_add_dialog_deps_section (PkTask *task,
gpk_dialog_tabbed_download_size_widget (tab_page, title, size);
gpk_dialog_tabbed_package_list_widget (tab_page, array_tmp);
gtk_notebook_append_page (tabbed_widget, tab_page, tab_label);
-out:
- if (array_tmp != NULL)
- g_ptr_array_unref (array_tmp);
- g_object_unref (sack_tmp);
}
static void
gpk_task_simulate_question (PkTask *task, guint request, PkResults *results)
{
gboolean ret;
- GPtrArray *array = NULL;
+ g_autoptr(GPtrArray) array = NULL;
GpkTaskPrivate *priv = GPK_TASK(task)->priv;
PkRoleEnum role;
- PkPackageSack *sack = NULL;
+ g_autoptr(PkPackageSack) sack = NULL;
guint inputs;
const gchar *title;
const gchar *message = NULL;
@@ -442,7 +416,7 @@ gpk_task_simulate_question (PkTask *task, guint request, PkResults *results)
if (!ret) {
g_debug ("we've said we don't want the dep dialog");
pk_task_user_accepted (PK_TASK(task), priv->request);
- goto out;
+ return;
}
}
@@ -521,11 +495,6 @@ gpk_task_simulate_question (PkTask *task, guint request, PkResults *results)
g_signal_connect (priv->current_window, "response", G_CALLBACK (gpk_task_dialog_response_cb), task);
gtk_widget_show_all (GTK_WIDGET(priv->current_window));
-out:
- if (sack != NULL)
- g_object_unref (sack);
- if (array != NULL)
- g_ptr_array_unref (array);
}
static void
@@ -534,14 +503,13 @@ gpk_task_setup_dialog_untrusted (GpkTask *task)
GtkWidget *widget;
GtkWidget *button;
guint retval;
- GError *error = NULL;
+ g_autoptr(GError) error = NULL;
/* get UI */
task->priv->builder_untrusted = gtk_builder_new ();
retval = gtk_builder_add_from_file (task->priv->builder_untrusted, GPK_DATA "/gpk-error.ui", &error);
if (retval == 0) {
g_warning ("failed to load ui: %s", error->message);
- g_error_free (error);
}
/* connect up default actions */
@@ -577,14 +545,13 @@ gpk_task_setup_dialog_signature (GpkTask *task)
{
GtkWidget *widget;
guint retval;
- GError *error = NULL;
+ g_autoptr(GError) error = NULL;
/* get UI */
task->priv->builder_signature = gtk_builder_new ();
retval = gtk_builder_add_from_file (task->priv->builder_signature, GPK_DATA "/gpk-signature.ui",
&error);
if (retval == 0) {
g_warning ("failed to load ui: %s", error->message);
- g_error_free (error);
}
/* connect up default actions */
@@ -607,14 +574,13 @@ gpk_task_setup_dialog_eula (GpkTask *task)
{
GtkWidget *widget;
guint retval;
- GError *error = NULL;
+ g_autoptr(GError) error = NULL;
/* get UI */
task->priv->builder_eula = gtk_builder_new ();
retval = gtk_builder_add_from_file (task->priv->builder_eula, GPK_DATA "/gpk-eula.ui", &error);
if (retval == 0) {
g_warning ("failed to load ui: %s", error->message);
- g_error_free (error);
}
/* connect up default actions */
diff --git a/src/gpk-update-viewer.c b/src/gpk-update-viewer.c
index 8d5927c..f81072e 100644
--- a/src/gpk-update-viewer.c
+++ b/src/gpk-update-viewer.c
@@ -188,7 +188,7 @@ gpk_update_viewer_check_restart (void)
const gchar *button;
GtkResponseType response;
gboolean show_button = TRUE;
- GError *error = NULL;
+ g_autoptr(GError) error = NULL;
/* get the text */
title = gpk_restart_enum_to_localised_text (restart_update);
@@ -218,7 +218,7 @@ gpk_update_viewer_check_restart (void)
} else {
g_warning ("unknown restart enum");
- goto out;
+ return FALSE;
}
/* show modal dialog */
@@ -247,7 +247,7 @@ gpk_update_viewer_check_restart (void)
/* cancel */
if (response != GTK_RESPONSE_OK)
- goto out;
+ return FALSE;
/* doing the action, return success */
ret = TRUE;
@@ -259,11 +259,9 @@ gpk_update_viewer_check_restart (void)
if (!ret) {
/* TRANSLATORS: the PackageKit request did not complete, and it did not send an error
*/
gpk_update_viewer_error_dialog (_("Could not restart"), NULL, error->message);
- g_error_free (error);
}
#endif
}
-out:
return ret;
}
@@ -274,16 +272,16 @@ gpk_update_viewer_check_blocked_packages (GPtrArray *array)
PkPackage *item;
GString *string;
gboolean exists = FALSE;
- gchar *text;
+ g_autofree gchar *text = NULL;
GtkWindow *window;
PkInfoEnum info;
- gchar *package_id = NULL;
- gchar *summary = NULL;
string = g_string_new ("");
/* find any that are blocked */
- for (i=0;i<array->len;i++) {
+ for (i = 0; i < array->len;i++) {
+ g_autofree gchar *package_id = NULL;
+ g_autofree gchar *summary = NULL;
item = g_ptr_array_index (array, i);
/* get data */
@@ -294,14 +292,11 @@ gpk_update_viewer_check_blocked_packages (GPtrArray *array)
NULL);
if (info == PK_INFO_ENUM_BLOCKED) {
- text = gpk_package_id_format_oneline (package_id, summary);
- g_string_append_printf (string, "%s\n", text);
- g_free (text);
+ g_autofree gchar *str = NULL;
+ str = gpk_package_id_format_oneline (package_id, summary);
+ g_string_append_printf (string, "%s\n", str);
exists = TRUE;
}
-
- g_free (package_id);
- g_free (summary);
}
/* trim off extra newlines */
@@ -313,14 +308,12 @@ gpk_update_viewer_check_blocked_packages (GPtrArray *array)
/* nothing of interest */
if (!exists)
- goto out;
+ return;
/* throw up dialog */
window = GTK_WINDOW(gtk_builder_get_object (builder, "dialog_updates"));
/* TRANSLATORS: we failed to install all the updates we requested */
gpk_error_dialog_modal (window, _("Some updates were not installed"), text, NULL);
-out:
- g_free (text);
}
static gboolean
@@ -339,7 +332,7 @@ gpk_update_viewer_are_all_updates_selected (GtkTreeModel *model)
GPK_UPDATES_COLUMN_SELECT, &selected,
-1);
if (!selected)
- goto out;
+ return FALSE;
/* do for children too */
child_valid = gtk_tree_model_iter_children (model, &child_iter, &iter);
@@ -348,27 +341,26 @@ gpk_update_viewer_are_all_updates_selected (GtkTreeModel *model)
GPK_UPDATES_COLUMN_SELECT, &selected,
-1);
if (!selected)
- goto out;
+ return FALSE;
child_valid = gtk_tree_model_iter_next (model, &child_iter);
}
valid = gtk_tree_model_iter_next (model, &iter);
}
-out:
- return selected;
+ return TRUE;
}
static void
gpk_update_viewer_update_packages_cb (PkTask *_task, GAsyncResult *res, gpointer user_data)
{
- PkResults *results;
- GError *error = NULL;
- GPtrArray *array = NULL;
+ g_autoptr(PkResults) results = NULL;
+ g_autoptr(GError) error = NULL;
+ g_autoptr(GPtrArray) array = NULL;
GtkWidget *dialog;
GtkWidget *widget;
PkRestartEnum restart;
- gchar *text;
- PkError *error_code = NULL;
+ g_autofree gchar *text = NULL;
+ g_autoptr(PkError) error_code = NULL;
GtkWindow *window;
gboolean ret;
const gchar *message;
@@ -394,7 +386,6 @@ gpk_update_viewer_update_packages_cb (PkTask *_task, GAsyncResult *res, gpointer
/* TRANSLATORS: the PackageKit request did not complete, and it did not send an error
*/
gpk_update_viewer_error_dialog (_("Could not update packages"), NULL, error->message);
}
- g_error_free (error);
/* re-enable the package list */
gpk_update_viewer_packages_set_sensitive (TRUE);
@@ -459,7 +450,6 @@ gpk_update_viewer_update_packages_cb (PkTask *_task, GAsyncResult *res, gpointer
/* TRANSLATORS: completed all updates */
text = g_strdup_printf ("<big><b>%s</b></big>", _("Updates installed"));
gtk_label_set_label (GTK_LABEL(widget), text);
- g_free (text);
/* do different text depending on if we deselected any */
treeview = GTK_TREE_VIEW(gtk_builder_get_object (builder, "treeview_updates"));
@@ -503,13 +493,6 @@ gpk_update_viewer_update_packages_cb (PkTask *_task, GAsyncResult *res, gpointer
out:
/* no longer updating */
ignore_updates_changed = FALSE;
-
- 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 GSList *active_rows = NULL;
@@ -573,12 +556,12 @@ gpk_update_viewer_add_active_row (GtkTreeModel *model, GtkTreePath *path)
/* check if already active */
ref = gtk_tree_row_reference_new (model, path);
if (ref == NULL)
- goto out;
+ return;
row = g_slist_find_custom (active_rows, (gconstpointer)ref,
(GCompareFunc)gpk_update_viewer_compare_refs);
if (row != NULL) {
g_debug ("already active");
gtk_tree_row_reference_free (ref);
- goto out;
+ return;
}
/* add poll */
@@ -587,8 +570,6 @@ gpk_update_viewer_add_active_row (GtkTreeModel *model, GtkTreePath *path)
g_source_set_name_by_id (active_row_timeout_id, "[GpkUpdateViewer] pulse row");
}
active_rows = g_slist_prepend (active_rows, ref);
-out:
- return;
}
static void
@@ -625,25 +606,22 @@ gpk_update_viewer_find_iter_model_cb (GtkTreeModel *model,
GtkTreeIter *iter,
const gchar *package_id)
{
- gchar *package_id_tmp = NULL;
+ g_autofree gchar *package_id_tmp = NULL;
GtkTreePath **_path = NULL;
- gboolean ret = FALSE;
gtk_tree_model_get (model, iter,
GPK_UPDATES_COLUMN_ID, &package_id_tmp,
-1);
if (package_id_tmp == NULL)
- goto out;
+ return FALSE;
/* match on the package id */
if (g_strcmp0 (package_id, package_id_tmp) == 0) {
_path = (GtkTreePath **) g_object_get_data (G_OBJECT(model), "_path");
*_path = gtk_tree_path_copy (path);
- ret = TRUE;
+ return TRUE;
}
-out:
- g_free (package_id_tmp);
- return ret;
+ return FALSE;
}
static GtkTreePath *
@@ -699,8 +677,7 @@ gpk_update_viewer_get_parent_for_info (PkInfoEnum info, GtkTreeIter *parent)
gboolean is_package;
gboolean ret = FALSE;
gboolean valid;
- gchar *package_id_tmp;
- gchar *title;
+ g_autofree gchar *title = NULL;
GtkTreeIter iter;
GtkTreeModel *model;
GtkTreeView *treeview;
@@ -724,12 +701,12 @@ gpk_update_viewer_get_parent_for_info (PkInfoEnum info, GtkTreeIter *parent)
/* find out how many we should update */
while (valid) {
+ g_autofree gchar *package_id_tmp = NULL;
gtk_tree_model_get (model, &iter,
GPK_UPDATES_COLUMN_INFO, &info_tmp,
GPK_UPDATES_COLUMN_ID, &package_id_tmp,
-1);
is_package = package_id_tmp != NULL;
- g_free (package_id_tmp);
/* right section? */
if (!is_package && info_tmp == info) {
@@ -761,7 +738,6 @@ gpk_update_viewer_get_parent_for_info (PkInfoEnum info, GtkTreeIter *parent)
GPK_UPDATES_COLUMN_PULSE, -1,
-1);
*parent = iter;
- g_free (title);
}
}
@@ -771,16 +747,15 @@ gpk_update_viewer_progress_cb (PkProgress *progress,
gpointer user_data)
{
gboolean allow_cancel;
- PkPackage *package;
- gchar *text;
+ g_autoptr(PkPackage) package = NULL;
gint percentage;
GtkWidget *widget;
guint64 transaction_flags;
PkInfoEnum info;
PkRoleEnum role;
PkStatusEnum status;
- gchar *package_id = NULL;
- gchar *summary = NULL;
+ g_autofree gchar *package_id = NULL;
+ g_autofree gchar *summary = NULL;
g_object_get (progress,
"role", &role,
@@ -802,11 +777,11 @@ gpk_update_viewer_progress_cb (PkProgress *progress,
/* ignore simulation phase */
if (pk_bitfield_contain (transaction_flags, PK_TRANSACTION_FLAG_ENUM_SIMULATE))
- goto out;
+ return;
/* add the results, not the progress */
if (role == PK_ROLE_ENUM_GET_UPDATES)
- goto out;
+ return;
g_object_get (package,
"info", &info,
@@ -839,7 +814,7 @@ gpk_update_viewer_progress_cb (PkProgress *progress,
/* update icon */
path = gpk_update_viewer_model_get_path (model, package_id);
if (path == NULL) {
-
+ g_autofree gchar *text = NULL;
text = gpk_package_id_format_twoline (gtk_widget_get_style_context (GTK_WIDGET
(treeview)),
package_id,
summary);
@@ -862,11 +837,10 @@ gpk_update_viewer_progress_cb (PkProgress *progress,
GPK_UPDATES_COLUMN_PERCENTAGE, 0,
GPK_UPDATES_COLUMN_PULSE, -1,
-1);
- g_free (text);
path = gpk_update_viewer_model_get_path (model, package_id);
if (path == NULL) {
g_warning ("found no package %s", package_id);
- goto out;
+ return;
}
}
@@ -911,7 +885,7 @@ gpk_update_viewer_progress_cb (PkProgress *progress,
GdkWindow *window;
const gchar *title;
GdkDisplay *display;
- GdkCursor *cursor;
+ g_autoptr(GdkCursor) cursor = NULL;
g_debug ("status %s", pk_status_enum_to_string (status));
@@ -929,7 +903,6 @@ gpk_update_viewer_progress_cb (PkProgress *progress,
display = gdk_display_get_default ();
cursor = gdk_cursor_new_for_display (display, GDK_WATCH);
gdk_window_set_cursor (window, cursor);
- g_object_unref (cursor);
}
/* set status */
@@ -981,7 +954,7 @@ gpk_update_viewer_progress_cb (PkProgress *progress,
/* ignore simulation phase */
if (pk_bitfield_contain (transaction_flags, PK_TRANSACTION_FLAG_ENUM_SIMULATE))
- goto out;
+ return;
g_object_get (progress,
"item-progress", &item_progress,
@@ -994,7 +967,7 @@ gpk_update_viewer_progress_cb (PkProgress *progress,
if (path == NULL) {
g_debug ("not found ID for %s",
pk_item_progress_get_package_id (item_progress));
- goto out;
+ return;
}
gtk_tree_model_get_iter (model, &iter, path);
@@ -1020,11 +993,6 @@ gpk_update_viewer_progress_cb (PkProgress *progress,
g_object_get (task, "idle", &idle, NULL);
gtk_widget_set_sensitive (widget, (allow_cancel || idle));
}
-out:
- g_free (summary);
- g_free (package_id);
- if (package != NULL)
- g_object_unref (package);
}
static void
@@ -1125,9 +1093,9 @@ static void
gpk_update_viewer_button_install_cb (GtkWidget *widget, gpointer user_data)
{
GtkTreeSelection *selection;
- GPtrArray *array = NULL;
+ g_autoptr(GPtrArray) array = NULL;
GtkTreeView *treeview;
- gchar **package_ids = NULL;
+ g_auto(GStrv) package_ids = NULL;
/* hide the upgrade viewbox from now on */
widget = GTK_WIDGET(gtk_builder_get_object (builder, "viewport_upgrade"));
@@ -1161,23 +1129,18 @@ gpk_update_viewer_button_install_cb (GtkWidget *widget, gpointer user_data)
/* from now on ignore updates-changed signals */
ignore_updates_changed = TRUE;
-
- g_strfreev (package_ids);
- if (array != NULL)
- g_ptr_array_unref (array);
}
static void
gpk_update_viewer_button_upgrade_cb (GtkWidget *widget, gpointer user_data)
{
gboolean ret;
- GError *error = NULL;
+ g_autoptr(GError) error = NULL;
ret = g_spawn_command_line_async ("/usr/share/PackageKit/pk-upgrade-distro.sh", &error);
if (!ret) {
/* TRANSLATORS: the PackageKit request did not complete, and it did not send an error */
gpk_update_viewer_error_dialog (_("Could not run upgrade script"), NULL, error->message);
- g_error_free (error);
}
}
@@ -1197,11 +1160,11 @@ gpk_update_viewer_check_mobile_broadband (void)
/* not on wireless mobile */
if (state != PK_NETWORK_ENUM_MOBILE)
- goto out;
+ return;
/* not when small */
if (size_total < GPK_UPDATE_VIEWER_MOBILE_SMALL_SIZE)
- goto out;
+ return;
/* TRANSLATORS, are we going to cost the user lots of money? */
message = ngettext ("Connectivity is being provided by wireless broadband, and it may be expensive to
update this package.",
@@ -1211,8 +1174,6 @@ gpk_update_viewer_check_mobile_broadband (void)
gtk_info_bar_set_message_type (GTK_INFO_BAR(info_mobile), GTK_MESSAGE_WARNING);
gtk_widget_show (info_mobile);
-out:
- return;
}
static void
@@ -1221,7 +1182,7 @@ gpk_update_viewer_update_global_state_recursive (GtkTreeModel *model, GtkTreeIte
gboolean selected;
PkRestartEnum restart;
guint size;
- gchar *package_id = NULL;
+ g_autofree gchar *package_id = NULL;
gboolean child_valid;
GtkTreeIter child_iter;
@@ -1244,7 +1205,6 @@ gpk_update_viewer_update_global_state_recursive (GtkTreeModel *model, GtkTreeIte
gpk_update_viewer_update_global_state_recursive (model, &child_iter);
child_valid = gtk_tree_model_iter_next (model, &child_iter);
}
- g_free (package_id);
}
static void
@@ -1276,7 +1236,7 @@ gpk_update_viewer_modal_error_with_timeout (const gchar *title, const gchar *mes
{
GtkWidget *dialog;
GtkWidget *widget;
- gchar *text;
+ g_autofree gchar *text = NULL;
/* hide close button */
widget = GTK_WIDGET(gtk_builder_get_object (builder, "button_quit"));
@@ -1287,7 +1247,6 @@ gpk_update_viewer_modal_error_with_timeout (const gchar *title, const gchar *mes
/* TRANSLATORS: there are no updates */
text = g_strdup_printf ("<big><b>%s</b></big>", _("There are no updates available"));
gtk_label_set_label (GTK_LABEL(widget), text);
- g_free (text);
/* show modal dialog */
widget = GTK_WIDGET(gtk_builder_get_object (builder, "dialog_updates"));
@@ -1324,8 +1283,8 @@ gpk_update_viewer_reconsider_info (void)
GtkWidget *widget;
guint len;
const gchar *title;
- gchar *text;
- gchar *text_size;
+ g_autofree gchar *text_total = NULL;
+ g_autofree gchar *text_markup = NULL;
PkNetworkEnum state;
/* update global state */
@@ -1398,12 +1357,10 @@ gpk_update_viewer_reconsider_info (void)
/* header */
widget = GTK_WIDGET(gtk_builder_get_object (builder, "label_header_title"));
- text = g_strdup_printf (ngettext ("There is %i update available",
- "There are %i updates available", len), len);
- text_size = g_strdup_printf ("<big><b>%s</b></big>", text);
- gtk_label_set_label (GTK_LABEL(widget), text_size);
- g_free (text);
- g_free (text_size);
+ text_total = g_strdup_printf (ngettext ("There is %i update available",
+ "There are %i updates available", len), len);
+ text_markup = g_strdup_printf ("<big><b>%s</b></big>", text_total);
+ gtk_label_set_label (GTK_LABEL(widget), text_markup);
widget = GTK_WIDGET(gtk_builder_get_object (builder, "hbox_header"));
gtk_widget_show (widget);
@@ -1413,21 +1370,21 @@ gpk_update_viewer_reconsider_info (void)
gtk_label_set_label (GTK_LABEL(widget), "");
} else {
if (size_total == 0) {
+ g_autofree gchar *text = NULL;
/* TRANSLATORS: how many updates are selected in the UI */
text = g_strdup_printf (ngettext ("%i update selected",
"%i updates selected",
number_total), number_total);
gtk_label_set_label (GTK_LABEL(widget), text);
- g_free (text);
} else {
+ g_autofree gchar *text = NULL;
+ g_autofree gchar *text_size = NULL;
text_size = g_format_size (size_total);
/* TRANSLATORS: how many updates are selected in the UI, and the size of packages to
download */
text = g_strdup_printf (ngettext ("%i update selected (%s)",
"%i updates selected (%s)",
number_total), number_total, text_size);
gtk_label_set_label (GTK_LABEL(widget), text);
- g_free (text);
- g_free (text_size);
}
}
@@ -1444,7 +1401,7 @@ gpk_update_viewer_treeview_update_toggled (GtkCellRendererToggle *cell, gchar *p
GtkTreePath *path = gtk_tree_path_new_from_string (path_str);
gboolean update;
gboolean child_valid;
- gchar *package_id;
+ g_autofree gchar *package_id = NULL;
GtkTreeView *treeview;
GtkTreeModel *model;
@@ -1460,7 +1417,6 @@ gpk_update_viewer_treeview_update_toggled (GtkCellRendererToggle *cell, gchar *p
update ^= 1;
g_debug ("update %s[%i]", package_id, update);
- g_free (package_id);
/* set new value */
gtk_tree_store_set (GTK_TREE_STORE(model), &iter, GPK_UPDATES_COLUMN_SELECT, update, -1);
@@ -1698,34 +1654,22 @@ gpk_update_viewer_add_description_link_item (GtkTextBuffer *buffer,
static gchar *
gpk_update_viewer_iso8601_format_locale_date (const gchar *iso_date)
{
- GDate *date = NULL;
+ g_autoptr(GDateTime) dt = NULL;
GTimeVal timeval;
- gboolean ret;
- gchar *text = NULL;
/* not valid */
if (iso_date == NULL || iso_date[0] == '\0')
- goto out;
+ return NULL;
/* parse ISO8601 date */
- ret = g_time_val_from_iso8601 (iso_date, &timeval);
- if (!ret) {
+ if (!g_time_val_from_iso8601 (iso_date, &timeval)) {
g_warning ("failed to parse %s, falling back to ISO8601", iso_date);
- text = g_strdup (iso_date);
- goto out;
+ return g_strdup (iso_date);
}
/* convert to a date object */
- date = g_date_new ();
- g_date_set_time_val (date, &timeval);
-
- /* pretty print it */
- text = g_new0 (gchar, 100);
- g_date_strftime (text, 100, "%x", date);
-out:
- if (date != NULL)
- g_date_free (date);
- return text;
+ dt = g_date_time_new_from_timeval_utc (&timeval);
+ return g_date_time_format (dt, "%x");
}
static void
@@ -1736,23 +1680,23 @@ gpk_update_viewer_populate_details (PkUpdateDetail *item)
GtkTreeModel *model;
GtkTreeIter treeiter;
PkInfoEnum info;
- gchar *line;
+ g_autofree gchar *line = NULL;
gchar *line2;
const gchar *title;
GtkTextIter iter;
gboolean has_update_text = FALSE;
- gchar *package_id;
- gchar **vendor_urls;
- gchar **bugzilla_urls;
- gchar **cve_urls;
+ g_autofree gchar *package_id = NULL;
+ g_auto(GStrv) vendor_urls = NULL;
+ g_auto(GStrv) bugzilla_urls = NULL;
+ g_auto(GStrv) cve_urls = NULL;
PkRestartEnum restart;
- gchar *update_text;
- gchar *changelog;
+ g_autofree gchar *update_text = NULL;
+ g_autofree gchar *changelog = NULL;
PkUpdateStateEnum state;
- gchar *issued;
- gchar *updated;
- gchar *issued_locale = NULL;
- gchar *updated_locale = NULL;
+ g_autofree gchar *issued = NULL;
+ g_autofree gchar *updated = NULL;
+ g_autofree gchar *issued_locale = NULL;
+ g_autofree gchar *updated_locale = NULL;
/* get data */
g_object_get (item,
@@ -1814,14 +1758,12 @@ gpk_update_viewer_populate_details (PkUpdateDetail *item)
line = g_strdup_printf (_("This notification was issued on %s and last updated on %s."),
issued_locale, updated_locale);
gtk_text_buffer_insert_with_tags_by_name (text_buffer, &iter, line, -1, "para", NULL);
gtk_text_buffer_insert (text_buffer, &iter, "\n", -1);
- g_free (line);
} else if (issued_locale != NULL) {
/* TRANSLATORS: this is when the update was issued */
line = g_strdup_printf (_("This notification was issued on %s."), issued_locale);
gtk_text_buffer_insert_with_tags_by_name (text_buffer, &iter, line, -1, "para", NULL);
gtk_text_buffer_insert (text_buffer, &iter, "\n", -1);
- g_free (line);
}
/* update text */
@@ -1887,24 +1829,13 @@ gpk_update_viewer_populate_details (PkUpdateDetail *item)
g_free (line2);
}
}
-
- g_free (package_id);
- g_strfreev (vendor_urls);
- g_strfreev (bugzilla_urls);
- g_strfreev (cve_urls);
- g_free (update_text);
- g_free (changelog);
- g_free (issued);
- g_free (updated);
- g_free (issued_locale);
- g_free (updated_locale);
}
static void
gpk_packages_treeview_clicked_cb (GtkTreeSelection *selection, gpointer user_data)
{
gboolean ret;
- gchar *package_id = NULL;
+ g_autofree gchar *package_id = NULL;
GtkTreeIter iter;
GtkTreeModel *model;
GtkWidget *widget;
@@ -1913,7 +1844,7 @@ gpk_packages_treeview_clicked_cb (GtkTreeSelection *selection, gpointer user_dat
/* This will only work in single or browse selection mode! */
ret = gtk_tree_selection_get_selected (selection, &model, &iter);
if (!ret)
- goto out;
+ return;
gtk_tree_model_get (model, &iter,
GPK_UPDATES_COLUMN_UPDATE_DETAIL_OBJ, &item,
@@ -1931,27 +1862,24 @@ gpk_packages_treeview_clicked_cb (GtkTreeSelection *selection, gpointer user_dat
} else {
gtk_text_buffer_set_text (text_buffer, _("No update details available."), -1);
}
-out:
- g_free (package_id);
}
static void
gpk_update_viewer_get_details_cb (PkClient *client, GAsyncResult *res, gpointer user_data)
{
- PkResults *results;
- GError *error = NULL;
- GPtrArray *array = NULL;
+ g_autoptr(PkResults) results = NULL;
+ g_autoptr(GError) error = NULL;
+ g_autoptr(GPtrArray) array = NULL;
PkDetails *item;
guint i;
guint64 size;
- gchar *package_id;
GtkWidget *widget;
GtkTreePath *path;
GtkTreeModel *model;
GtkTreeSelection *selection;
GtkTreeView *treeview;
GtkTreeIter iter;
- PkError *error_code = NULL;
+ g_autoptr(PkError) error_code = NULL;
GtkWindow *window;
/* get the results */
@@ -1959,8 +1887,7 @@ gpk_update_viewer_get_details_cb (PkClient *client, GAsyncResult *res, gpointer
if (results == NULL) {
/* TRANSLATORS: the PackageKit request did not complete, and it did not send an error */
gpk_update_viewer_error_dialog (_("Could not get update details"), NULL, error->message);
- g_error_free (error);
- goto out;
+ return;
}
/* check error code */
@@ -1971,7 +1898,7 @@ gpk_update_viewer_get_details_cb (PkClient *client, GAsyncResult *res, gpointer
window = GTK_WINDOW(gtk_builder_get_object (builder, "dialog_updates"));
gpk_error_dialog_modal (window, gpk_error_enum_to_localised_text (pk_error_get_code
(error_code)),
gpk_error_enum_to_localised_message (pk_error_get_code (error_code)),
pk_error_get_details (error_code));
- goto out;
+ return;
}
/* get data */
@@ -1979,13 +1906,14 @@ gpk_update_viewer_get_details_cb (PkClient *client, GAsyncResult *res, gpointer
if (array->len == 0) {
/* TRANSLATORS: PackageKit did not send any results for the query... */
gpk_update_viewer_error_dialog (_("Could not get package details"), _("No results were
returned."), NULL);
- goto out;
+ return;
}
/* set data */
treeview = GTK_TREE_VIEW(gtk_builder_get_object (builder, "treeview_updates"));
model = gtk_tree_view_get_model (treeview);
- for (i=0; i<array->len; i++) {
+ for (i = 0; i < array->len; i++) {
+ g_autofree gchar *package_id = NULL;
item = g_ptr_array_index (array, i);
/* get data */
@@ -2010,7 +1938,6 @@ gpk_update_viewer_get_details_cb (PkClient *client, GAsyncResult *res, gpointer
gtk_tree_store_set (array_store_updates, &iter,
GPK_UPDATES_COLUMN_STATUS, GPK_INFO_ENUM_DOWNLOADED, -1);
}
- g_free (package_id);
}
/* select the first entry in the updates array now we've got data */
@@ -2023,30 +1950,22 @@ gpk_update_viewer_get_details_cb (PkClient *client, GAsyncResult *res, gpointer
/* set info */
gpk_update_viewer_reconsider_info ();
-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
gpk_update_viewer_get_update_detail_cb (PkClient *client, GAsyncResult *res, gpointer user_data)
{
- PkResults *results;
- GError *error = NULL;
- GPtrArray *array = NULL;
+ g_autoptr(PkResults) results = NULL;
+ g_autoptr(GError) error = NULL;
+ g_autoptr(GPtrArray) array = NULL;
PkUpdateDetail *item;
guint i;
GtkTreeView *treeview;
GtkTreeModel *model;
GtkTreeIter iter;
GtkTreePath *path;
- PkError *error_code = NULL;
+ g_autoptr(PkError) error_code = NULL;
GtkWindow *window;
- gchar *package_id;
PkRestartEnum restart;
/* get the results */
@@ -2054,8 +1973,7 @@ gpk_update_viewer_get_update_detail_cb (PkClient *client, GAsyncResult *res, gpo
if (results == NULL) {
/* TRANSLATORS: the PackageKit request did not complete, and it did not send an error */
gpk_update_viewer_error_dialog (_("Could not get update details"), NULL, error->message);
- g_error_free (error);
- goto out;
+ return;
}
/* check error code */
@@ -2066,7 +1984,7 @@ gpk_update_viewer_get_update_detail_cb (PkClient *client, GAsyncResult *res, gpo
window = GTK_WINDOW(gtk_builder_get_object (builder, "dialog_updates"));
gpk_error_dialog_modal (window, gpk_error_enum_to_localised_text (pk_error_get_code
(error_code)),
gpk_error_enum_to_localised_message (pk_error_get_code (error_code)),
pk_error_get_details (error_code));
- goto out;
+ return;
}
/* get data */
@@ -2074,13 +1992,14 @@ gpk_update_viewer_get_update_detail_cb (PkClient *client, GAsyncResult *res, gpo
if (array->len == 0) {
/* TRANSLATORS: PackageKit did not send any results for the query... */
gpk_update_viewer_error_dialog (_("Could not get update details"), _("No results were
returned."), NULL);
- goto out;
+ return;
}
/* add data */
treeview = GTK_TREE_VIEW(gtk_builder_get_object (builder, "treeview_updates"));
model = gtk_tree_view_get_model (treeview);
- for (i=0; i<array->len; i++) {
+ for (i = 0; i < array->len; i++) {
+ g_autofree gchar *package_id = NULL;
item = g_ptr_array_index (array, i);
/* get data */
@@ -2099,15 +2018,7 @@ gpk_update_viewer_get_update_detail_cb (PkClient *client, GAsyncResult *res, gpo
GPK_UPDATES_COLUMN_UPDATE_DETAIL_OBJ, (gpointer) g_object_ref
(item),
GPK_UPDATES_COLUMN_RESTART, restart, -1);
}
- g_free (package_id);
}
-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
@@ -2371,7 +2282,7 @@ gpk_update_viewer_packages_to_ids (GPtrArray *array)
const gchar *package_id;
value = g_new0 (gchar *, array->len + 1);
- for (i=0; i<array->len; i++) {
+ for (i = 0; i < array->len; i++) {
item = g_ptr_array_index (array, i);
package_id = pk_package_get_id (item);
value[i] = g_strdup (package_id);
@@ -2382,35 +2293,30 @@ gpk_update_viewer_packages_to_ids (GPtrArray *array)
static void
gpk_update_viewer_get_updates_cb (PkClient *client, GAsyncResult *res, gpointer user_data)
{
- PkResults *results;
- PkPackageSack *sack = NULL;
- GError *error = NULL;
- GPtrArray *array = NULL;
- GPtrArray *array_messages = NULL;
+ g_autoptr(PkResults) results = NULL;
+ g_autoptr(PkPackageSack) sack = NULL;
+ g_autoptr(GError) error = NULL;
+ g_autoptr(GPtrArray) array = NULL;
+ g_autoptr(GPtrArray) array_messages = NULL;
PkPackage *item;
- gchar *text = NULL;
gboolean selected;
gboolean sensitive;
GtkTreeIter iter;
GtkTreeIter parent;
guint i;
- gchar **package_ids;
GtkTreeView *treeview;
GtkTreeModel *model;
GtkWidget *widget;
- PkError *error_code = NULL;
+ g_autoptr(PkError) error_code = NULL;
GtkWindow *window;
PkInfoEnum info;
- gchar *package_id = NULL;
- gchar *summary = NULL;
/* get the results */
results = pk_client_generic_finish (client, res, &error);
if (results == NULL) {
/* TRANSLATORS: the PackageKit request did not complete, and it did not send an error */
gpk_update_viewer_error_dialog (_("Could not get updates"), NULL, error->message);
- g_error_free (error);
- goto out;
+ return;
}
/* check error code */
@@ -2421,7 +2327,7 @@ gpk_update_viewer_get_updates_cb (PkClient *client, GAsyncResult *res, gpointer
window = GTK_WINDOW(gtk_builder_get_object (builder, "dialog_updates"));
gpk_error_dialog_modal (window, gpk_error_enum_to_localised_text (pk_error_get_code
(error_code)),
gpk_error_enum_to_localised_message (pk_error_get_code (error_code)),
pk_error_get_details (error_code));
- goto out;
+ return;
}
/* get data */
@@ -2429,7 +2335,10 @@ gpk_update_viewer_get_updates_cb (PkClient *client, GAsyncResult *res, gpointer
pk_package_sack_sort (sack, PK_PACKAGE_SACK_SORT_TYPE_NAME);
array = pk_package_sack_get_array (sack);
widget = GTK_WIDGET(gtk_builder_get_object (builder, "treeview_updates"));
- for (i=0; i<array->len; i++) {
+ for (i = 0; i < array->len; i++) {
+ g_autofree gchar *text = NULL;
+ g_autofree gchar *package_id = NULL;
+ g_autofree gchar *summary = NULL;
item = g_ptr_array_index (array, i);
/* get data */
@@ -2474,9 +2383,6 @@ gpk_update_viewer_get_updates_cb (PkClient *client, GAsyncResult *res, gpointer
GPK_UPDATES_COLUMN_PERCENTAGE, 0,
GPK_UPDATES_COLUMN_PULSE, -1,
-1);
- g_free (text);
- g_free (package_id);
- g_free (summary);
}
/* get the download sizes */
@@ -2494,6 +2400,7 @@ gpk_update_viewer_get_updates_cb (PkClient *client, GAsyncResult *res, gpointer
/* get the download sizes */
if (update_array->len > 0) {
+ g_auto(GStrv) package_ids = NULL;
package_ids = gpk_update_viewer_packages_to_ids (array);
/* get the details of all the packages */
@@ -2505,8 +2412,6 @@ gpk_update_viewer_get_updates_cb (PkClient *client, GAsyncResult *res, gpointer
pk_client_get_details_async (PK_CLIENT(task), package_ids, cancellable,
(PkProgressCallback) gpk_update_viewer_progress_cb, NULL,
(GAsyncReadyCallback) gpk_update_viewer_get_details_cb, NULL);
-
- g_strfreev (package_ids);
}
/* are now able to do action */
@@ -2515,18 +2420,6 @@ gpk_update_viewer_get_updates_cb (PkClient *client, GAsyncResult *res, gpointer
/* set info */
gpk_update_viewer_reconsider_info ();
-
-out:
- if (error_code != NULL)
- g_object_unref (error_code);
- if (array != NULL)
- g_ptr_array_unref (array);
- if (array_messages != NULL)
- g_ptr_array_unref (array_messages);
- if (sack != NULL)
- g_object_unref (sack);
- if (results != NULL)
- g_object_unref (results);
}
static gboolean
@@ -2534,7 +2427,7 @@ gpk_update_viewer_get_new_update_array (void)
{
gboolean ret;
GtkWidget *widget;
- gchar *text = NULL;
+ g_autofree gchar *text = NULL;
PkBitfield filter = PK_FILTER_ENUM_NONE;
/* clear all widgets */
@@ -2557,7 +2450,6 @@ gpk_update_viewer_get_new_update_array (void)
pk_client_get_updates_async (PK_CLIENT(task), filter, cancellable,
(PkProgressCallback) gpk_update_viewer_progress_cb, NULL,
(GAsyncReadyCallback) gpk_update_viewer_get_updates_cb, NULL);
- g_free (text);
return ret;
}
@@ -2644,9 +2536,10 @@ gpk_update_viewer_textview_event_after (GtkWidget *text_view, GdkEvent *ev)
static void
gpk_update_viewer_textview_set_cursor (GtkTextView *text_view, gint x, gint y)
{
- GSList *tags = NULL, *tagp = NULL;
+ g_autoptr(GSList) tags = NULL;
+ GSList *tagp = NULL;
GtkTextIter iter;
- GdkCursor *cursor;
+ g_autoptr(GdkCursor) cursor = NULL;
gboolean hovering = FALSE;
gboolean hovering_over_link = FALSE;
@@ -2671,11 +2564,7 @@ gpk_update_viewer_textview_set_cursor (GtkTextView *text_view, gint x, gint y)
else
cursor = gdk_cursor_new_for_display (gdk_display_get_default (), GDK_XTERM);
gdk_window_set_cursor (gtk_text_view_get_window (text_view, GTK_TEXT_WINDOW_TEXT), cursor);
- g_object_unref (cursor);
}
-
- if (tags != NULL)
- g_slist_free (tags);
}
static gboolean
@@ -2704,7 +2593,7 @@ gpk_update_viewer_textview_visibility_notify_event (GtkWidget *text_view, GdkEve
window = gtk_widget_get_window (text_view);
device = gdk_event_get_device ((const GdkEvent *) event);
if (device == NULL)
- goto out;
+ return FALSE;
gdk_window_get_device_position (window,
device,
&wx, &wy,
@@ -2712,7 +2601,6 @@ gpk_update_viewer_textview_visibility_notify_event (GtkWidget *text_view, GdkEve
gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (text_view), GTK_TEXT_WINDOW_WIDGET, wx, wy,
&bx, &by);
gpk_update_viewer_textview_set_cursor (GTK_TEXT_VIEW (text_view), bx, by);
-out:
return FALSE;
}
@@ -2731,9 +2619,9 @@ gpk_update_viewer_updates_changed_cb (PkControl *_control, gpointer user_data)
static gboolean
gpk_update_viewer_search_equal_func (GtkTreeModel *model, gint column, const gchar *key, GtkTreeIter *iter,
gpointer search_data)
{
- char *text;
- char *cn_key;
- char *cn_text;
+ g_autofree gchar *text = NULL;
+ g_autofree gchar *cn_key = NULL;
+ g_autofree gchar *cn_text = NULL;
gboolean result;
gtk_tree_model_get (model, iter, column, &text, -1);
@@ -2745,11 +2633,6 @@ gpk_update_viewer_search_equal_func (GtkTreeModel *model, gint column, const gch
result = FALSE;
else
result = TRUE;
-
- g_free (text);
- g_free (cn_key);
- g_free (cn_text);
-
return result;
}
@@ -2761,7 +2644,7 @@ gpk_update_viewer_get_distro_upgrades_best (GPtrArray *array)
PkDistroUpgradeEnum state;
/* find a stable update */
- for (i=0; i<array->len; i++) {
+ for (i = 0; i < array->len; i++) {
item = g_ptr_array_index (array, i);
/* get data */
@@ -2770,25 +2653,23 @@ gpk_update_viewer_get_distro_upgrades_best (GPtrArray *array)
NULL);
if (state == PK_DISTRO_UPGRADE_ENUM_STABLE)
- goto out;
+ return item;
}
- item = NULL;
-out:
- return item;
+ return NULL;
}
static void
gpk_update_viewer_get_distro_upgrades_cb (PkClient *client, GAsyncResult *res, gpointer user_data)
{
- PkResults *results;
- GError *error = NULL;
- GPtrArray *array = NULL;
+ g_autoptr(PkResults) results = NULL;
+ g_autoptr(GError) error = NULL;
+ g_autoptr(GPtrArray) array = NULL;
PkDistroUpgrade *item;
- gchar *text = NULL;
- gchar *text_format = NULL;
- gchar *summary = NULL;
+ g_autofree gchar *text = NULL;
+ g_autofree gchar *text_format = NULL;
+ g_autofree gchar *summary = NULL;
GtkWidget *widget;
- PkError *error_code = NULL;
+ g_autoptr(PkError) error_code = NULL;
GtkWindow *window;
/* get the results */
@@ -2796,8 +2677,7 @@ gpk_update_viewer_get_distro_upgrades_cb (PkClient *client, GAsyncResult *res, g
if (results == NULL) {
/* TRANSLATORS: the PackageKit request did not complete, and it did not send an error */
gpk_update_viewer_error_dialog (_("Could not get list of distribution upgrades"), NULL,
error->message);
- g_error_free (error);
- goto out;
+ return;
}
/* check error code */
@@ -2808,14 +2688,14 @@ gpk_update_viewer_get_distro_upgrades_cb (PkClient *client, GAsyncResult *res, g
window = GTK_WINDOW(gtk_builder_get_object (builder, "dialog_updates"));
gpk_error_dialog_modal (window, gpk_error_enum_to_localised_text (pk_error_get_code
(error_code)),
gpk_error_enum_to_localised_message (pk_error_get_code (error_code)),
pk_error_get_details (error_code));
- goto out;
+ return;
}
/* get data */
array = pk_results_get_distro_upgrade_array (results);
item = gpk_update_viewer_get_distro_upgrades_best (array);
if (item == NULL)
- goto out;
+ return;
/* get data */
g_object_get (item,
@@ -2837,22 +2717,12 @@ gpk_update_viewer_get_distro_upgrades_cb (PkClient *client, GAsyncResult *res, g
/* get model */
gpk_update_viewer_reconsider_info ();
-out:
- g_free (summary);
- g_free (text);
- g_free (text_format);
- 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
gpk_update_viewer_get_properties_cb (PkControl *_control, GAsyncResult *res, gpointer user_data)
{
- GError *error = NULL;
+ g_autoptr(GError) error = NULL;
gboolean ret;
/* get the result */
@@ -2860,9 +2730,8 @@ gpk_update_viewer_get_properties_cb (PkControl *_control, GAsyncResult *res, gpo
if (!ret) {
/* TRANSLATORS: backend is broken, and won't tell us what it supports */
g_print ("%s: %s\n", _("Exiting as backend details could not be retrieved"), error->message);
- g_error_free (error);
gpk_update_viewer_quit ();
- goto out;
+ return;
}
/* get values */
@@ -2876,8 +2745,6 @@ gpk_update_viewer_get_properties_cb (PkControl *_control, GAsyncResult *res, gpo
(PkProgressCallback) gpk_update_viewer_progress_cb, NULL,
(GAsyncReadyCallback)
gpk_update_viewer_get_distro_upgrades_cb, NULL);
}
-out:
- return;
}
static void
@@ -2904,7 +2771,7 @@ gpk_update_viewer_application_startup_cb (GtkApplication *_application, gpointer
GtkTreeSelection *selection;
gboolean ret;
guint retval;
- GError *error = NULL;
+ g_autoptr(GError) error = NULL;
auto_shutdown_id = 0;
size_total = 0;
@@ -2941,8 +2808,7 @@ gpk_update_viewer_application_startup_cb (GtkApplication *_application, gpointer
retval = gtk_builder_add_from_file (builder, GPK_DATA "/gpk-update-viewer.ui", &error);
if (retval == 0) {
g_warning ("failed to load ui: %s", error->message);
- g_error_free (error);
- goto out;
+ return;
}
main_window = GTK_WIDGET(gtk_builder_get_object (builder, "dialog_updates"));
@@ -3070,8 +2936,6 @@ gpk_update_viewer_application_startup_cb (GtkApplication *_application, gpointer
/* show window */
gtk_widget_show (main_window);
-out:
- return;
}
int
diff --git a/src/systemd-proxy.c b/src/systemd-proxy.c
index adad6fe..a0020cc 100644
--- a/src/systemd-proxy.c
+++ b/src/systemd-proxy.c
@@ -91,7 +91,7 @@ gboolean
systemd_proxy_restart (SystemdProxy *proxy,
GError **error)
{
- GDBusConnection *bus;
+ g_autoptr(GDBusConnection) bus = NULL;
bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, NULL);
g_dbus_connection_call_sync (bus,
@@ -101,7 +101,5 @@ systemd_proxy_restart (SystemdProxy *proxy,
"Reboot",
g_variant_new ("(b)", TRUE),
NULL, 0, G_MAXINT, NULL, NULL);
- g_object_unref (bus);
-
return TRUE;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]