[nautilus] bookmark: Use g_auto* macros
- From: Ernestas Kulik <ernestask src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus] bookmark: Use g_auto* macros
- Date: Wed, 4 Jul 2018 07:10:48 +0000 (UTC)
commit c7d29f7d966dcd805cdcdba06444a5aa3cff4dad
Author: Yi-Soo An <yisooan gmail com>
Date: Wed Jul 4 13:20:06 2018 +0900
bookmark: Use g_auto* macros
According to the documentation, the variables with these macros
are cleaned up in a way appropriate to its type when the variables
go out of scope.
src/nautilus-bookmark.c | 39 ++++++++++++---------------------------
1 file changed, 12 insertions(+), 27 deletions(-)
---
diff --git a/src/nautilus-bookmark.c b/src/nautilus-bookmark.c
index 6c731d42b..f115f2487 100644
--- a/src/nautilus-bookmark.c
+++ b/src/nautilus-bookmark.c
@@ -97,7 +97,7 @@ static void
bookmark_set_name_from_ready_file (NautilusBookmark *self,
NautilusFile *file)
{
- gchar *display_name;
+ g_autofree gchar *display_name = NULL;
if (self->has_custom_name)
{
@@ -119,15 +119,13 @@ bookmark_set_name_from_ready_file (NautilusBookmark *self,
nautilus_bookmark_set_name_internal (self, display_name);
DEBUG ("%s: name changed to %s", nautilus_bookmark_get_name (self), display_name);
}
-
- g_free (display_name);
}
static void
bookmark_file_changed_callback (NautilusFile *file,
NautilusBookmark *bookmark)
{
- GFile *location;
+ g_autoptr (GFile) location = NULL;
g_assert (file == bookmark->file);
@@ -147,8 +145,6 @@ bookmark_file_changed_callback (NautilusFile *file,
g_signal_emit (bookmark, signals[CONTENTS_CHANGED], 0);
}
- g_object_unref (location);
-
if (nautilus_file_is_gone (file) ||
nautilus_file_is_in_trash (file))
{
@@ -178,8 +174,9 @@ static void
apply_warning_emblem (GIcon **base,
gboolean symbolic)
{
- GIcon *warning, *emblemed_icon;
- GEmblem *emblem;
+ GIcon *emblemed_icon;
+ g_autoptr (GIcon) warning = NULL;
+ g_autoptr (GEmblem) emblem = NULL;
if (symbolic)
{
@@ -193,8 +190,6 @@ apply_warning_emblem (GIcon **base,
emblem = g_emblem_new (warning);
emblemed_icon = g_emblemed_icon_new (*base, emblem);
- g_object_unref (emblem);
- g_object_unref (warning);
g_object_unref (*base);
*base = emblemed_icon;
@@ -302,8 +297,8 @@ out:
static void
nautilus_bookmark_set_icon_to_default (NautilusBookmark *bookmark)
{
- GIcon *icon, *symbolic_icon;
- char *uri;
+ g_autoptr (GIcon) icon = NULL;
+ g_autoptr (GIcon) symbolic_icon = NULL;
if (g_file_is_native (bookmark->location))
{
@@ -312,10 +307,8 @@ nautilus_bookmark_set_icon_to_default (NautilusBookmark *bookmark)
}
else
{
- uri = nautilus_bookmark_get_uri (bookmark);
symbolic_icon = g_themed_icon_new (NAUTILUS_ICON_FOLDER_REMOTE);
icon = g_themed_icon_new (NAUTILUS_ICON_FULLCOLOR_FOLDER_REMOTE);
- g_free (uri);
}
if (!bookmark->exists)
@@ -332,9 +325,6 @@ nautilus_bookmark_set_icon_to_default (NautilusBookmark *bookmark)
"icon", icon,
"symbolic-icon", symbolic_icon,
NULL);
-
- g_object_unref (icon);
- g_object_unref (symbolic_icon);
}
static void
@@ -435,26 +425,23 @@ exists_query_info_ready_cb (GObject *source,
GAsyncResult *res,
gpointer user_data)
{
- GFileInfo *info;
+ g_autoptr (GFileInfo) info = NULL;
NautilusBookmark *bookmark;
- GError *error = NULL;
+ g_autoptr (GError) error = NULL;
gboolean exists = FALSE;
info = g_file_query_info_finish (G_FILE (source), res, &error);
if (!info && g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
{
- g_clear_error (&error);
return;
}
- g_clear_error (&error);
bookmark = user_data;
if (info)
{
exists = TRUE;
- g_object_unref (info);
g_clear_object (&bookmark->cancellable);
}
@@ -793,13 +780,11 @@ nautilus_bookmark_get_location (NautilusBookmark *bookmark)
char *
nautilus_bookmark_get_uri (NautilusBookmark *bookmark)
{
- GFile *file;
- char *uri;
+ g_autoptr (GFile) file = NULL;
file = nautilus_bookmark_get_location (bookmark);
- uri = g_file_get_uri (file);
- g_object_unref (file);
- return uri;
+
+ return g_file_get_uri (file);
}
NautilusBookmark *
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]