[gnome-initial-setup: 1/2] Use g_auto()/g_autoptr() more



commit d3c9565233f9a2ee9de21e631e2dc856b720f6f9
Author: Matthew Leeds <mwl458 gmail com>
Date:   Thu Mar 19 15:01:47 2020 +0000

    Use g_auto()/g_autoptr() more
    
    We already depend on a new enough GLib for these.

 gnome-initial-setup/gis-keyring.c                  | 46 ++++++----------------
 gnome-initial-setup/meson.build                    |  2 +-
 .../pages/language/cc-language-chooser.c           |  6 +--
 .../pages/language/gis-welcome-widget.c            |  6 +--
 4 files changed, 17 insertions(+), 43 deletions(-)
---
diff --git a/gnome-initial-setup/gis-keyring.c b/gnome-initial-setup/gis-keyring.c
index 16e2d3c..7035e6f 100644
--- a/gnome-initial-setup/gis-keyring.c
+++ b/gnome-initial-setup/gis-keyring.c
@@ -42,53 +42,43 @@
 void
 gis_ensure_login_keyring ()
 {
-       GSubprocess *subprocess = NULL;
-       GSubprocessLauncher *launcher = NULL;
-       GError *error = NULL;
+       g_autoptr(GSubprocess) subprocess = NULL;
+       g_autoptr(GSubprocessLauncher) launcher = NULL;
+       g_autoptr(GError) error = NULL;
 
        g_debug ("launching gnome-keyring-daemon --unlock");
        launcher = g_subprocess_launcher_new (G_SUBPROCESS_FLAGS_STDIN_PIPE | G_SUBPROCESS_FLAGS_STDOUT_PIPE 
| G_SUBPROCESS_FLAGS_STDERR_SILENCE);
        subprocess = g_subprocess_launcher_spawn (launcher, &error, "gnome-keyring-daemon", "--unlock", NULL);
        if (subprocess == NULL) {
                g_warning ("Failed to spawn gnome-keyring-daemon --unlock: %s", error->message);
-               g_error_free (error);
-               goto out;
+               return;
        }
 
        if (!g_subprocess_communicate_utf8 (subprocess, DUMMY_PWD, NULL, NULL, NULL, &error)) {
                g_warning ("Failed to communicate with gnome-keyring-daemon: %s", error->message);
-               g_error_free (error);
-               goto out;
+               return;
        }
-
-out:
-       if (subprocess)
-               g_object_unref (subprocess);
-       if (launcher)
-               g_object_unref (launcher);
 }
 
 void
 gis_update_login_keyring_password (const gchar *new_)
 {
-       GDBusConnection *bus = NULL;
-       SecretService *service = NULL;
-       SecretValue *old_secret = NULL;
-       SecretValue *new_secret = NULL;
-       GError *error = NULL;
+       g_autoptr(GDBusConnection) bus = NULL;
+       g_autoptr(SecretService) service = NULL;
+       g_autoptr(SecretValue) old_secret = NULL;
+       g_autoptr(SecretValue) new_secret = NULL;
+       g_autoptr(GError) error = NULL;
        
        service = secret_service_get_sync (SECRET_SERVICE_OPEN_SESSION, NULL, &error);
        if (service == NULL) {
                g_warning ("Failed to get secret service: %s", error->message);
-               g_error_free (error);
-               goto out;
+               return;
        }
 
        bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
        if (bus == NULL) {
                g_warning ("Failed to get session bus: %s", error->message);
-               g_error_free (error);
-               goto out;
+               return;
        }
 
        old_secret = secret_value_new (DUMMY_PWD, strlen (DUMMY_PWD), "text/plain");
@@ -110,17 +100,5 @@ gis_update_login_keyring_password (const gchar *new_)
 
         if (error != NULL) {
           g_warning ("Failed to change keyring password: %s", error->message);
-          g_error_free (error);
         }
-
-out:
-
-       if (service)
-               g_object_unref (service);
-       if (bus)
-               g_object_unref (bus);
-       if (old_secret)
-               secret_value_unref (old_secret);
-       if (new_secret)
-               secret_value_unref (new_secret);
 }
diff --git a/gnome-initial-setup/meson.build b/gnome-initial-setup/meson.build
index 5f83bfe..9a721df 100644
--- a/gnome-initial-setup/meson.build
+++ b/gnome-initial-setup/meson.build
@@ -46,7 +46,7 @@ dependencies = [
     dependency ('rest-0.7'),
     dependency ('json-glib-1.0'),
     dependency ('krb5'),
-    dependency ('libsecret-1'),
+    dependency ('libsecret-1', version: '>= 0.18.8'),
     dependency ('pwquality'),
     dependency ('webkit2gtk-4.0'),
     cheese_dep,
diff --git a/gnome-initial-setup/pages/language/cc-language-chooser.c 
b/gnome-initial-setup/pages/language/cc-language-chooser.c
index 3722de1..fa8531c 100644
--- a/gnome-initial-setup/pages/language/cc-language-chooser.c
+++ b/gnome-initial-setup/pages/language/cc-language-chooser.c
@@ -296,14 +296,12 @@ add_languages (CcLanguageChooser  *chooser,
 static void
 add_all_languages (CcLanguageChooser *chooser)
 {
-        char **locale_ids;
-        GHashTable *initial;
+        g_auto(GStrv) locale_ids = NULL;
+        g_autoptr(GHashTable) initial = NULL;
 
         locale_ids = gnome_get_all_locales ();
         initial = cc_common_language_get_initial_languages ();
         add_languages (chooser, locale_ids, initial);
-        g_hash_table_destroy (initial);
-        g_strfreev (locale_ids);
 }
 
 static gboolean
diff --git a/gnome-initial-setup/pages/language/gis-welcome-widget.c 
b/gnome-initial-setup/pages/language/gis-welcome-widget.c
index 7f030bd..6f6b8b0 100644
--- a/gnome-initial-setup/pages/language/gis-welcome-widget.c
+++ b/gnome-initial-setup/pages/language/gis-welcome-widget.c
@@ -155,10 +155,10 @@ static void
 fill_stack (GisWelcomeWidget *widget)
 {
   GisWelcomeWidgetPrivate *priv = gis_welcome_widget_get_instance_private (widget);
-  GHashTable *initial = cc_common_language_get_initial_languages ();
+  g_autoptr(GHashTable) initial = cc_common_language_get_initial_languages ();
   GHashTableIter iter;
   gpointer key, value;
-  GHashTable *added_translations;
+  g_autoptr(GHashTable) added_translations = NULL;
 
   added_translations = g_hash_table_new (g_str_hash, g_str_equal);
 
@@ -183,8 +183,6 @@ fill_stack (GisWelcomeWidget *widget)
 
       g_hash_table_insert (priv->translation_widgets, locale_id, label);
     }
-
-  g_hash_table_destroy (added_translations);
 }
 
 static void


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