[gnome-control-center] background: Use g_autoptr to remove an explicit unref



commit ff342dfbc72a2ba32c001869a169379f477f2ce8
Author: Robert Ancell <robert ancell canonical com>
Date:   Tue Oct 15 17:12:13 2019 +1300

    background: Use g_autoptr to remove an explicit unref

 panels/background/bg-recent-source.c | 24 ++++++++++--------------
 1 file changed, 10 insertions(+), 14 deletions(-)
---
diff --git a/panels/background/bg-recent-source.c b/panels/background/bg-recent-source.c
index 13e583fdc..06e0b68df 100644
--- a/panels/background/bg-recent-source.c
+++ b/panels/background/bg-recent-source.c
@@ -331,7 +331,8 @@ on_file_copied_cb (GObject      *source,
                    GAsyncResult *result,
                    gpointer      user_data)
 {
-  BgRecentSource *self = BG_RECENT_SOURCE (user_data);
+  g_autoptr(BgRecentSource) self = BG_RECENT_SOURCE (user_data);
+  g_autofree gchar *original_file = NULL;
   g_autoptr(GError) error = NULL;
 
   g_file_copy_finish (G_FILE (source), result, &error);
@@ -340,14 +341,11 @@ on_file_copied_cb (GObject      *source,
     {
       if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
         g_critical ("Failed to copy file: %s", error->message);
-    }
-  else
-    {
-      g_autofree gchar *original_file = g_file_get_path (G_FILE (source));
-      g_debug ("Successfully copied wallpaper: %s", original_file);
+      return;
     }
 
-  g_object_unref (self);
+   original_file = g_file_get_path (G_FILE (source));
+   g_debug ("Successfully copied wallpaper: %s", original_file);
 }
 
 static void
@@ -355,7 +353,8 @@ on_file_deleted_cb (GObject      *source,
                     GAsyncResult *result,
                     gpointer      user_data)
 {
-  BgRecentSource *self = BG_RECENT_SOURCE (user_data);
+  g_autoptr(BgRecentSource) self = BG_RECENT_SOURCE (user_data);
+  g_autofree gchar *original_file = NULL;
   g_autoptr(GError) error = NULL;
 
   g_file_delete_finish (G_FILE (source), result, &error);
@@ -364,14 +363,11 @@ on_file_deleted_cb (GObject      *source,
     {
       if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
         g_critical ("Failed to delete wallpaper: %s", error->message);
-    }
-  else
-    {
-      g_autofree gchar *original_file = g_file_get_path (G_FILE (source));
-      g_debug ("Successfully deleted wallpaper: %s", original_file);
+      return;
     }
 
-  g_object_unref (self);
+  original_file = g_file_get_path (G_FILE (source));
+  g_debug ("Successfully deleted wallpaper: %s", original_file);
 }
 
 /* GObject overrides */


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