[gnome-control-center] network: Use g_autoptr for unref code



commit e70610fe740e9ed081e6271648a2916aeb9ac376
Author: Robert Ancell <robert ancell canonical com>
Date:   Thu Sep 12 11:53:42 2019 +1200

    network: Use g_autoptr for unref code

 panels/network/cc-network-panel.c                  | 20 +++---
 panels/network/cc-wifi-panel.c                     | 17 ++---
 .../connection-editor/ce-page-8021x-security.c     |  4 +-
 panels/network/connection-editor/ce-page-details.c |  8 +--
 .../network/connection-editor/ce-page-security.c   | 10 +--
 panels/network/connection-editor/ce-page-wifi.c    |  5 +-
 panels/network/connection-editor/ce-page.c         |  9 +--
 panels/network/connection-editor/ce-page.h         |  2 +
 .../connection-editor/net-connection-editor.c      |  6 +-
 panels/network/connection-editor/vpn-helpers.c     |  9 +--
 panels/network/net-device-ethernet.c               | 26 +++----
 panels/network/net-device-mobile.c                 | 17 ++---
 panels/network/net-device-wifi.c                   | 82 +++++++---------------
 panels/network/net-proxy.c                         | 33 +++++----
 panels/network/network-dialogs.c                   |  6 +-
 panels/network/wireless-security/eap-method-fast.c | 22 ++----
 panels/network/wireless-security/eap-method-fast.h |  3 +
 panels/network/wireless-security/eap-method-leap.h |  3 +
 panels/network/wireless-security/eap-method-peap.c | 25 +++----
 panels/network/wireless-security/eap-method-peap.h |  3 +
 .../network/wireless-security/eap-method-simple.h  |  3 +
 panels/network/wireless-security/eap-method-tls.c  |  3 +-
 panels/network/wireless-security/eap-method-tls.h  |  3 +
 panels/network/wireless-security/eap-method-ttls.c | 37 ++++------
 panels/network/wireless-security/eap-method-ttls.h |  5 +-
 panels/network/wireless-security/eap-method.c      | 22 ++----
 panels/network/wireless-security/eap-method.h      |  2 +
 .../network/wireless-security/wireless-security.c  | 52 +++++---------
 .../network/wireless-security/wireless-security.h  |  2 +
 29 files changed, 165 insertions(+), 274 deletions(-)
---
diff --git a/panels/network/cc-network-panel.c b/panels/network/cc-network-panel.c
index b57de1026..20d5ab21f 100644
--- a/panels/network/cc-network-panel.c
+++ b/panels/network/cc-network-panel.c
@@ -175,7 +175,7 @@ cc_network_panel_set_property (GObject      *object,
 
                 parameters = g_value_get_variant (value);
                 if (parameters) {
-                        GPtrArray *array;
+                        g_autoptr(GPtrArray) array = NULL;
                         const gchar **args;
                         array = variant_av_to_string_array (parameters);
                         args = (const gchar **) array->pdata;
@@ -191,10 +191,8 @@ cc_network_panel_set_property (GObject      *object,
 
                         if (verify_argv (self, (const char **) args) == FALSE) {
                                 reset_command_line_args (self);
-                                g_ptr_array_unref (array);
                                 return;
                         }
-                        g_ptr_array_unref (array);
                         g_debug ("Calling handle_argv() after setting property");
                         handle_argv (self);
                 }
@@ -368,20 +366,21 @@ handle_argv (CcNetworkPanel *panel)
 
         for (i = 0; i < panel->devices->len; i++) {
                 GObject *object_tmp;
-                NMDevice *device;
-                NMConnection *connection;
                 gboolean done = FALSE;
 
                 object_tmp = g_ptr_array_index (panel->devices, i);
 
                 if (NET_IS_DEVICE (object_tmp)) {
+                        NMDevice *device = NULL; /* Autoptr macro not available: 
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/270 */
+
                         g_object_get (object_tmp, "nm-device", &device, NULL);
                         done = handle_argv_for_device (panel, device);
                         g_object_unref (device);
                 } else if (NET_IS_VPN (object_tmp)) {
+                        g_autoptr(NMConnection) connection = NULL;
+
                         g_object_get (object_tmp, "connection", &connection, NULL);
                         done = handle_argv_for_connection (panel, connection);
-                        g_object_unref (connection);
                 }
 
                 if (done)
@@ -502,7 +501,7 @@ panel_add_device (CcNetworkPanel *panel, NMDevice *device)
 
         if (type == NM_DEVICE_TYPE_MODEM &&
             g_str_has_prefix (nm_device_get_udi (device), "/org/freedesktop/ModemManager1/Modem/")) {
-                GDBusObject *modem_object;
+                g_autoptr(GDBusObject) modem_object;
 
                 if (panel->modem_manager == NULL) {
                         g_warning ("Cannot grab information for modem at %s: No ModemManager support",
@@ -522,7 +521,6 @@ panel_add_device (CcNetworkPanel *panel, NMDevice *device)
                 g_object_set (net_device,
                               "mm-object", modem_object,
                               NULL);
-                g_object_unref (modem_object);
         }
 
         /* add as a panel */
@@ -858,7 +856,7 @@ cc_network_panel_init (CcNetworkPanel *panel)
 {
         g_autoptr(GError) error = NULL;
         GtkWidget *toplevel;
-        GDBusConnection *system_bus;
+        g_autoptr(GDBusConnection) system_bus = NULL;
         const GPtrArray *connections;
         guint i;
 
@@ -875,9 +873,8 @@ cc_network_panel_init (CcNetworkPanel *panel)
 
         /* Create and store a NMClient instance if it doesn't exist yet */
         if (!cc_object_storage_has_object (CC_OBJECT_NMCLIENT)) {
-                NMClient *client = nm_client_new (NULL, NULL);
+                g_autoptr(NMClient) client = nm_client_new (NULL, NULL);
                 cc_object_storage_add_object (CC_OBJECT_NMCLIENT, client);
-                g_object_unref (client);
         }
 
         /* use NetworkManager client */
@@ -905,7 +902,6 @@ cc_network_panel_init (CcNetworkPanel *panel)
                 if (panel->modem_manager == NULL)
                         g_warning ("Error connecting to ModemManager: %s",
                                    error->message);
-                g_object_unref (system_bus);
         }
 
         /* add remote settings such as VPN settings as virtual devices */
diff --git a/panels/network/cc-wifi-panel.c b/panels/network/cc-wifi-panel.c
index 4c8495a2e..4e80effa6 100644
--- a/panels/network/cc-wifi-panel.c
+++ b/panels/network/cc-wifi-panel.c
@@ -121,16 +121,15 @@ update_panel_visibility (NMClient *client)
 void
 cc_wifi_panel_static_init_func (void)
 {
-  NMClient *client;
+  g_autoptr(NMClient) client = NULL;
 
   g_debug ("Monitoring NetworkManager for Wi-Fi devices");
 
   /* Create and store a NMClient instance if it doesn't exist yet */
   if (!cc_object_storage_has_object (CC_OBJECT_NMCLIENT))
     {
-      client = nm_client_new (NULL, NULL);
-      cc_object_storage_add_object (CC_OBJECT_NMCLIENT, client);
-      g_object_unref (client);
+      g_autoptr(NMClient) new_client = nm_client_new (NULL, NULL);
+      cc_object_storage_add_object (CC_OBJECT_NMCLIENT, new_client);
     }
 
   client = cc_object_storage_get_object (CC_OBJECT_NMCLIENT);
@@ -141,8 +140,6 @@ cc_wifi_panel_static_init_func (void)
   g_signal_connect (client, "device-removed", G_CALLBACK (update_panel_visibility), NULL);
 
   update_panel_visibility (client);
-
-  g_object_unref (client);
 }
 
 /* Auxiliary methods */
@@ -649,7 +646,7 @@ cc_wifi_panel_set_property (GObject      *object,
 
       if (parameters)
         {
-          GPtrArray *array;
+          g_autoptr(GPtrArray) array = NULL;
           const gchar **args;
 
           array = variant_av_to_string_array (parameters);
@@ -677,12 +674,9 @@ cc_wifi_panel_set_property (GObject      *object,
           if (!verify_argv (self, (const char **) args))
             {
               reset_command_line_args (self);
-              g_ptr_array_unref (array);
               return;
             }
 
-          g_ptr_array_unref (array);
-
           handle_argv (self);
         }
       break;
@@ -737,9 +731,8 @@ cc_wifi_panel_init (CcWifiPanel *self)
   /* Create and store a NMClient instance if it doesn't exist yet */
   if (!cc_object_storage_has_object (CC_OBJECT_NMCLIENT))
     {
-      NMClient *client = nm_client_new (NULL, NULL);
+      g_autoptr(NMClient) client = nm_client_new (NULL, NULL);
       cc_object_storage_add_object (CC_OBJECT_NMCLIENT, client);
-      g_object_unref (client);
     }
 
   /* Load NetworkManager */
diff --git a/panels/network/connection-editor/ce-page-8021x-security.c 
b/panels/network/connection-editor/ce-page-8021x-security.c
index f7d31969a..d53f18e86 100644
--- a/panels/network/connection-editor/ce-page-8021x-security.c
+++ b/panels/network/connection-editor/ce-page-8021x-security.c
@@ -120,12 +120,12 @@ validate (CEPage *cepage, NMConnection *connection, GError **error)
        gboolean valid = TRUE;
 
        if (gtk_switch_get_active (page->enabled)) {
-               NMConnection *tmp_connection;
                NMSetting *s_8021x;
 
                /* FIXME: get failed property and error out of wireless security objects */
                valid = wireless_security_validate (page->security, error);
                if (valid) {
+                       g_autoptr(NMConnection) tmp_connection = NULL;
                        NMSetting *s_con;
 
                        /* Here's a nice hack to work around the fact that ws_802_1x_fill_connection needs 
wireless setting. */
@@ -142,8 +142,6 @@ validate (CEPage *cepage, NMConnection *connection, GError **error)
 
                        s_8021x = nm_connection_get_setting (tmp_connection, NM_TYPE_SETTING_802_1X);
                        nm_connection_add_setting (connection, NM_SETTING (g_object_ref (s_8021x)));
-
-                       g_object_unref (tmp_connection);
                }
        } else {
                nm_connection_remove_setting (connection, NM_TYPE_SETTING_802_1X);
diff --git a/panels/network/connection-editor/ce-page-details.c 
b/panels/network/connection-editor/ce-page-details.c
index ea9e06e28..d7bfa5499 100644
--- a/panels/network/connection-editor/ce-page-details.c
+++ b/panels/network/connection-editor/ce-page-details.c
@@ -80,8 +80,8 @@ static void
 update_last_used (CEPageDetails *page, NMConnection *connection)
 {
         g_autofree gchar *last_used = NULL;
-        GDateTime *now = NULL;
-        GDateTime *then = NULL;
+        g_autoptr(GDateTime) now = NULL;
+        g_autoptr(GDateTime) then = NULL;
         gint days;
         GTimeSpan diff;
         guint64 timestamp;
@@ -110,10 +110,6 @@ update_last_used (CEPageDetails *page, NMConnection *connection)
                 last_used = g_strdup_printf (ngettext ("%i day ago", "%i days ago", days), days);
 out:
         panel_set_device_widget_details (CE_PAGE (page)->builder, "last_used", last_used);
-        if (now != NULL)
-                g_date_time_unref (now);
-        if (then != NULL)
-                g_date_time_unref (then);
 }
 
 static void
diff --git a/panels/network/connection-editor/ce-page-security.c 
b/panels/network/connection-editor/ce-page-security.c
index d06e3aeb1..7aefc457e 100644
--- a/panels/network/connection-editor/ce-page-security.c
+++ b/panels/network/connection-editor/ce-page-security.c
@@ -125,7 +125,7 @@ security_combo_changed (GtkComboBox *combo,
         CEPageSecurity *page = CE_PAGE_SECURITY (user_data);
         GtkWidget *vbox;
         GList *l, *children;
-        WirelessSecurity *sec;
+        g_autoptr(WirelessSecurity) sec = NULL;
 
         wsec_size_group_clear (page->group);
 
@@ -150,7 +150,6 @@ security_combo_changed (GtkComboBox *combo,
                 wireless_security_add_to_size_group (sec, page->group);
 
                 gtk_container_add (GTK_CONTAINER (vbox), sec_widget);
-                wireless_security_unref (sec);
         }
 
         ce_page_changed (CE_PAGE (page));
@@ -204,7 +203,7 @@ finish_setup (CEPageSecurity *page)
         NMSettingWireless *sw;
         NMSettingWirelessSecurity *sws;
         gboolean is_adhoc = FALSE;
-        GtkListStore *sec_model;
+        g_autoptr(GtkListStore) sec_model = NULL;
         GtkTreeIter iter;
         const gchar *mode;
         guint32 dev_caps = 0;
@@ -345,7 +344,6 @@ finish_setup (CEPageSecurity *page)
         gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (combo), renderer, set_sensitive, &page->adhoc, 
NULL);
 
         gtk_combo_box_set_active (combo, active < 0 ? 0 : (guint32) active);
-        g_object_unref (G_OBJECT (sec_model));
 
         page->security_combo = combo;
 
@@ -360,7 +358,7 @@ validate (CEPage        *page,
           GError       **error)
 {
         NMSettingWireless *sw;
-        WirelessSecurity *sec;
+        g_autoptr(WirelessSecurity) sec = NULL;
         gboolean valid = FALSE;
         const char *mode;
 
@@ -393,8 +391,6 @@ validate (CEPage        *page,
                                 valid = FALSE;
                         }
                 }
-
-                wireless_security_unref (sec);
         } else {
                 /* No security, unencrypted */
                 nm_connection_remove_setting (connection, NM_TYPE_SETTING_WIRELESS_SECURITY);
diff --git a/panels/network/connection-editor/ce-page-wifi.c b/panels/network/connection-editor/ce-page-wifi.c
index 50afdc0cd..b16364955 100644
--- a/panels/network/connection-editor/ce-page-wifi.c
+++ b/panels/network/connection-editor/ce-page-wifi.c
@@ -93,7 +93,7 @@ connect_wifi_page (CEPageWifi *page)
 static void
 ui_to_setting (CEPageWifi *page)
 {
-        GBytes *ssid;
+        g_autoptr(GBytes) ssid = NULL;
         const gchar *utf8_ssid, *bssid;
         GtkWidget *entry;
         GtkComboBoxText *combo;
@@ -122,9 +122,6 @@ ui_to_setting (CEPageWifi *page)
                       NM_SETTING_WIRELESS_MAC_ADDRESS, device_mac,
                       NM_SETTING_WIRELESS_CLONED_MAC_ADDRESS, cloned_mac,
                       NULL);
-
-        if (ssid)
-                g_bytes_unref (ssid);
 }
 
 static gboolean
diff --git a/panels/network/connection-editor/ce-page.c b/panels/network/connection-editor/ce-page.c
index 263e22fa4..9cc9e1b4b 100644
--- a/panels/network/connection-editor/ce-page.c
+++ b/panels/network/connection-editor/ce-page.c
@@ -221,7 +221,7 @@ ce_page_new (GType             type,
              const gchar      *ui_resource,
              const gchar      *title)
 {
-        CEPage *page;
+        g_autoptr(CEPage) page = NULL;
         g_autoptr(GError) error = NULL;
 
         page = CE_PAGE (g_object_new (type,
@@ -233,20 +233,18 @@ ce_page_new (GType             type,
         if (ui_resource) {
                 if (!gtk_builder_add_from_resource (page->builder, ui_resource, &error)) {
                         g_warning ("Couldn't load builder file: %s", error->message);
-                        g_object_unref (page);
                         return NULL;
                 }
                 page->page = GTK_WIDGET (gtk_builder_get_object (page->builder, "page"));
                 if (!page->page) {
                         g_warning ("Couldn't load page widget from %s", ui_resource);
-                        g_object_unref (page);
                         return NULL;
                 }
 
                 g_object_ref_sink (page->page);
         }
 
-        return page;
+        return g_steal_pointer (&page);
 }
 
 static void
@@ -265,7 +263,7 @@ ce_page_complete_init (CEPage      *page,
                        GError      *error)
 {
        g_autoptr(GError) update_error = NULL;
-       GVariant *setting_dict;
+       g_autoptr(GVariant) setting_dict = NULL;
        gboolean ignore_error = FALSE;
 
        g_return_if_fail (page != NULL);
@@ -295,7 +293,6 @@ ce_page_complete_init (CEPage      *page,
                emit_initialized (page, NULL);
                return;
        }
-       g_variant_unref (setting_dict);
 
        /* Update the connection with the new secrets */
        if (nm_connection_update_secrets (page->connection,
diff --git a/panels/network/connection-editor/ce-page.h b/panels/network/connection-editor/ce-page.h
index bf00679ec..d7df04dc0 100644
--- a/panels/network/connection-editor/ce-page.h
+++ b/panels/network/connection-editor/ce-page.h
@@ -111,6 +111,8 @@ gchar * ce_page_get_next_available_name (const GPtrArray *connections,
                                          const gchar *type_name);
 
 
+G_DEFINE_AUTOPTR_CLEANUP_FUNC (CEPage, g_object_unref)
+
 
 G_END_DECLS
 
diff --git a/panels/network/connection-editor/net-connection-editor.c 
b/panels/network/connection-editor/net-connection-editor.c
index 278957b70..1db3880ff 100644
--- a/panels/network/connection-editor/net-connection-editor.c
+++ b/panels/network/connection-editor/net-connection-editor.c
@@ -73,11 +73,10 @@ cancel_clicked_cb (NetConnectionEditor *editor)
 static void
 update_connection (NetConnectionEditor *editor)
 {
-        GVariant *settings;
+        g_autoptr(GVariant) settings = NULL;
 
         settings = nm_connection_to_dbus (editor->connection, NM_CONNECTION_SERIALIZE_ALL);
         nm_connection_replace_settings (editor->orig_connection, settings, NULL);
-        g_variant_unref (settings);
 }
 
 static void
@@ -843,11 +842,10 @@ net_connection_editor_forget (NetConnectionEditor *editor)
 void
 net_connection_editor_reset (NetConnectionEditor *editor)
 {
-        GVariant *settings;
+        g_autoptr(GVariant) settings = NULL;
 
         settings = nm_connection_to_dbus (editor->orig_connection, NM_CONNECTION_SERIALIZE_ALL);
         nm_connection_replace_settings (editor->connection, settings, NULL);
-        g_variant_unref (settings);
 }
 
 void
diff --git a/panels/network/connection-editor/vpn-helpers.c b/panels/network/connection-editor/vpn-helpers.c
index 04c67bc5b..6ed8791bb 100644
--- a/panels/network/connection-editor/vpn-helpers.c
+++ b/panels/network/connection-editor/vpn-helpers.c
@@ -64,13 +64,13 @@ vpn_get_plugins (void)
        p = nm_vpn_plugin_info_list_load ();
        plugins = NULL;
        while (p) {
-               NMVpnPluginInfo *plugin_info = NM_VPN_PLUGIN_INFO (p->data);
+               g_autoptr(NMVpnPluginInfo) plugin_info = NM_VPN_PLUGIN_INFO (p->data);
                g_autoptr(GError) error = NULL;
 
                /* load the editor plugin, and preserve only those NMVpnPluginInfo that can
                 * successfully load the plugin. */
                if (nm_vpn_plugin_info_load_editor_plugin (plugin_info, &error))
-                       plugins = g_slist_prepend (plugins, plugin_info);
+                       plugins = g_slist_prepend (plugins, g_steal_pointer (&plugin_info));
                else {
                        if (   !nm_vpn_plugin_info_get_plugin (plugin_info)
                            && nm_vpn_plugin_info_lookup_property (plugin_info, 
NM_VPN_PLUGIN_INFO_KF_GROUP_GNOME, "properties")) {
@@ -88,7 +88,6 @@ vpn_get_plugins (void)
                                           nm_vpn_plugin_info_get_filename (plugin_info),
                                           error->message);
                        }
-                       g_object_unref (plugin_info);
                }
                p = g_slist_delete_link (p, p);
        }
@@ -194,7 +193,7 @@ vpn_import (GtkWindow *parent, VpnImportCallback callback, gpointer user_data)
 static void
 export_vpn_to_file_cb (GtkWidget *dialog, gint response, gpointer user_data)
 {
-       NMConnection *connection = NM_CONNECTION (user_data);
+       g_autoptr(NMConnection) connection = NM_CONNECTION (user_data);
        char *filename = NULL;
        g_autoptr(GError) error = NULL;
        NMVpnEditorPlugin *plugin;
@@ -273,8 +272,6 @@ done:
        }
 
 out:
-       g_object_unref (connection);
-
        gtk_widget_hide (dialog);
        gtk_widget_destroy (dialog);
 }
diff --git a/panels/network/net-device-ethernet.c b/panels/network/net-device-ethernet.c
index bd5f8a9f1..86c87ab30 100644
--- a/panels/network/net-device-ethernet.c
+++ b/panels/network/net-device-ethernet.c
@@ -107,9 +107,8 @@ add_details_row (GtkWidget *details, gint top, const gchar *heading, const gchar
 static gchar *
 get_last_used_string (NMConnection *connection)
 {
-        gchar *last_used = NULL;
-        GDateTime *now = NULL;
-        GDateTime *then = NULL;
+        g_autoptr(GDateTime) now = NULL;
+        g_autoptr(GDateTime) then = NULL;
         gint days;
         GTimeSpan diff;
         guint64 timestamp;
@@ -117,12 +116,10 @@ get_last_used_string (NMConnection *connection)
 
         s_con = nm_connection_get_setting_connection (connection);
         if (s_con == NULL)
-                goto out;
+                return NULL;
         timestamp = nm_setting_connection_get_timestamp (s_con);
-        if (timestamp == 0) {
-                last_used = g_strdup (_("never"));
-                goto out;
-        }
+        if (timestamp == 0)
+                return g_strdup (_("never"));
 
         /* calculate the amount of time that has elapsed */
         now = g_date_time_new_now_utc ();
@@ -130,18 +127,11 @@ get_last_used_string (NMConnection *connection)
         diff = g_date_time_difference  (now, then);
         days = diff / G_TIME_SPAN_DAY;
         if (days == 0)
-                last_used = g_strdup (_("today"));
+                return g_strdup (_("today"));
         else if (days == 1)
-                last_used = g_strdup (_("yesterday"));
+                return g_strdup (_("yesterday"));
         else
-                last_used = g_strdup_printf (ngettext ("%i day ago", "%i days ago", days), days);
-out:
-        if (now != NULL)
-                g_date_time_unref (now);
-        if (then != NULL)
-                g_date_time_unref (then);
-
-        return last_used;
+                return g_strdup_printf (ngettext ("%i day ago", "%i days ago", days), days);
 }
 
 static void
diff --git a/panels/network/net-device-mobile.c b/panels/network/net-device-mobile.c
index b98a3907a..69868a371 100644
--- a/panels/network/net-device-mobile.c
+++ b/panels/network/net-device-mobile.c
@@ -480,8 +480,8 @@ device_mobile_device_got_modem_manager_cb (GObject *source_object,
                                            gpointer user_data)
 {
         g_autoptr(GError) error = NULL;
-        GVariant *result = NULL;
-        GDBusProxy *proxy;
+        g_autoptr(GVariant) result = NULL;
+        g_autoptr(GDBusProxy) proxy = NULL;
         NetDeviceMobile *device_mobile = (NetDeviceMobile *)user_data;
 
         proxy = g_dbus_proxy_new_for_bus_finish (res, &error);
@@ -496,16 +496,13 @@ device_mobile_device_got_modem_manager_cb (GObject *source_object,
                                                    "EquipmentIdentifier");
 
         /* save */
-        if (result) {
+        if (result)
                 g_object_set_data_full (G_OBJECT (device_mobile),
                                         "ControlCenter::EquipmentIdentifier",
                                         g_variant_dup_string (result, NULL),
                                         g_free);
-                g_variant_unref (result);
-        }
 
         device_mobile_refresh_equipment_id (device_mobile);
-        g_object_unref (proxy);
 }
 
 static void
@@ -535,7 +532,7 @@ device_mobile_get_registration_info_cb (GObject      *source_object,
         g_autofree gchar *operator_code = NULL;
         g_autoptr(GError) error = NULL;
         guint registration_status;
-        GVariant *result = NULL;
+        g_autoptr(GVariant) result = NULL;
         g_autofree gchar *operator_name = NULL;
         NetDeviceMobile *device_mobile = (NetDeviceMobile *)user_data;
 
@@ -562,8 +559,6 @@ device_mobile_get_registration_info_cb (GObject      *source_object,
         device_mobile_save_operator_name (device_mobile,
                                           "ControlCenter::OperatorNameGsm",
                                           operator_name);
-
-        g_variant_unref (result);
 }
 
 static void
@@ -637,7 +632,7 @@ device_mobile_get_serving_system_cb (GObject      *source_object,
                                      gpointer      user_data)
 {
         NetDeviceMobile *device_mobile = (NetDeviceMobile *)user_data;
-        GVariant *result = NULL;
+        g_autoptr(GVariant) result = NULL;
         g_autoptr(GError) error = NULL;
 
         guint32 band_class;
@@ -664,8 +659,6 @@ device_mobile_get_serving_system_cb (GObject      *source_object,
         device_mobile_save_operator_name (device_mobile,
                                           "ControlCenter::OperatorNameCdma",
                                           operator_name);
-
-        g_variant_unref (result);
 }
 
 static void
diff --git a/panels/network/net-device-wifi.c b/panels/network/net-device-wifi.c
index 68065ab5a..d66492a94 100644
--- a/panels/network/net-device-wifi.c
+++ b/panels/network/net-device-wifi.c
@@ -199,7 +199,7 @@ static NMConnection *
 find_connection_for_device (NetDeviceWifi *device_wifi,
                             NMDevice       *device)
 {
-        NetDevice *tmp;
+        g_autoptr(NetDevice) tmp = NULL;
         NMConnection *connection;
         NMClient *client;
 
@@ -209,7 +209,6 @@ find_connection_for_device (NetDeviceWifi *device_wifi,
                             "nm-device", device,
                             NULL);
         connection = net_device_get_find_connection (tmp);
-        g_object_unref (tmp);
         return connection;
 }
 
@@ -382,8 +381,8 @@ static void
 update_last_used (NetDeviceWifi *device_wifi, NMConnection *connection)
 {
         g_autofree gchar *last_used = NULL;
-        GDateTime *now = NULL;
-        GDateTime *then = NULL;
+        g_autoptr(GDateTime) now = NULL;
+        g_autoptr(GDateTime) then = NULL;
         gint days;
         GTimeSpan diff;
         guint64 timestamp;
@@ -413,10 +412,6 @@ out:
         panel_set_device_widget_details (device_wifi->builder,
                                          "last_used",
                                          last_used);
-        if (now != NULL)
-                g_date_time_unref (now);
-        if (then != NULL)
-                g_date_time_unref (then);
 }
 
 static void
@@ -705,14 +700,14 @@ wireless_try_to_connect (NetDeviceWifi *device_wifi,
         GCancellable *cancellable;
 
         if (device_wifi->updating_device)
-                goto out;
+                return;
 
         if (ap_object_path == NULL || ap_object_path[0] == 0)
-                goto out;
+                return;
 
         device = net_device_get_nm_device (NET_DEVICE (device_wifi));
         if (device == NULL)
-                goto out;
+                return;
 
         ssid_target = nm_utils_escape_ssid ((gpointer) g_bytes_get_data (ssid, NULL), g_bytes_get_size 
(ssid));
         g_debug ("try to connect to WIFI network %s [%s]",
@@ -723,16 +718,14 @@ wireless_try_to_connect (NetDeviceWifi *device_wifi,
         cancellable = net_object_get_cancellable (NET_OBJECT (device_wifi));
 
         if (!is_8021x (device, ap_object_path)) {
-                GPermission *permission;
+                g_autoptr(GPermission) permission = NULL;
                 gboolean allowed_to_share = FALSE;
-                NMConnection *partial = NULL;
+                g_autoptr(NMConnection) partial = NULL;
 
                 permission = polkit_permission_new_sync 
("org.freedesktop.NetworkManager.settings.modify.system",
                                                          NULL, NULL, NULL);
-                if (permission) {
+                if (permission)
                         allowed_to_share = g_permission_get_allowed (permission);
-                        g_object_unref (permission);
-                }
 
                 if (!allowed_to_share) {
                         NMSettingConnection *s_con;
@@ -751,11 +744,9 @@ wireless_try_to_connect (NetDeviceWifi *device_wifi,
                                                              cancellable,
                                                              connection_add_activate_cb,
                                                              device_wifi);
-                if (!allowed_to_share)
-                        g_object_unref (partial);
         } else {
                 CcNetworkPanel *panel;
-                GVariantBuilder *builder;
+                g_autoptr(GVariantBuilder) builder = NULL;
                 GVariant *parameters;
 
                 g_debug ("no existing connection found for %s, creating", ssid_target);
@@ -767,20 +758,15 @@ wireless_try_to_connect (NetDeviceWifi *device_wifi,
 
                 panel = net_object_get_panel (NET_OBJECT (device_wifi));
                 g_object_set (G_OBJECT (panel), "parameters", parameters, NULL);
-
-                g_variant_builder_unref (builder);
         }
-out:
-        return;
 }
 
 static gchar *
 get_hostname (void)
 {
-        GDBusConnection *bus;
-        GVariant *res;
-        GVariant *inner;
-        gchar *str;
+        g_autoptr(GDBusConnection) bus = NULL;
+        g_autoptr(GVariant) res = NULL;
+        g_autoptr(GVariant) inner = NULL;
         g_autoptr(GError) error = NULL;
 
         bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
@@ -801,21 +787,14 @@ get_hostname (void)
                                            -1,
                                            NULL,
                                            &error);
-        g_object_unref (bus);
 
-        if (res == NULL)
+        if (res == NULL) {
                 g_warning ("Getting pretty hostname failed: %s", error->message);
-
-        str = NULL;
-
-        if (res != NULL) {
-                g_variant_get (res, "(v)", &inner);
-                str = g_variant_dup_string (inner, NULL);
-                g_variant_unref (inner);
-                g_variant_unref (res);
+                return NULL;
         }
 
-        return str;
+        g_variant_get (res, "(v)", &inner);
+        return g_variant_dup_string (inner, NULL);
 }
 
 static GBytes *
@@ -1026,13 +1005,14 @@ overwrite_ssid_cb (GObject      *source_object,
 static void
 start_shared_connection (NetDeviceWifi *device_wifi)
 {
-        NMConnection *c;
+        NMConnection *hotspot_connection;
+        g_autoptr(NMConnection) c = NULL;
         NMSettingConnection *sc;
         NMSettingWireless *sw;
         NMSettingIP4Config *sip;
         NMSettingWirelessSecurity *sws;
         NMDevice *device;
-        GBytes *ssid;
+        g_autoptr(GBytes) ssid = NULL;
         const gchar *str_mac;
         struct ether_addr *bin_mac;
         NMClient *client;
@@ -1043,22 +1023,21 @@ start_shared_connection (NetDeviceWifi *device_wifi)
         device = net_device_get_nm_device (NET_DEVICE (device_wifi));
         g_assert (nm_device_get_device_type (device) == NM_DEVICE_TYPE_WIFI);
 
-        c = net_device_wifi_get_hotspot_connection (device_wifi);
+        hotspot_connection = net_device_wifi_get_hotspot_connection (device_wifi);
 
         ssid = generate_ssid_for_hotspot (device_wifi);
 
         client = net_object_get_client (NET_OBJECT (device_wifi));
         cancellable = net_object_get_cancellable (NET_OBJECT (device_wifi));
-        if (c != NULL) {
+        if (hotspot_connection != NULL) {
                 NMSettingWireless *sw;
                 const char *c_path;
                 NMRemoteConnection *connection;
 
-                sw = nm_connection_get_setting_wireless (c);
+                sw = nm_connection_get_setting_wireless (hotspot_connection);
                 g_object_set (sw, "ssid", ssid, NULL);
-                g_bytes_unref (ssid);
 
-                c_path = nm_connection_get_path (c);
+                c_path = nm_connection_get_path (hotspot_connection);
                 connection = nm_client_get_connection_by_path (client, c_path);
 
                 g_debug ("overwriting ssid to %s", (char *) g_bytes_get_data (ssid, NULL));
@@ -1099,14 +1078,13 @@ start_shared_connection (NetDeviceWifi *device_wifi)
         str_mac = nm_device_wifi_get_permanent_hw_address (NM_DEVICE_WIFI (device));
         bin_mac = ether_aton (str_mac);
         if (bin_mac) {
-                GByteArray *hw_address;
+                g_autoptr(GByteArray) hw_address = NULL;
 
                 hw_address = g_byte_array_sized_new (ETH_ALEN);
                 g_byte_array_append (hw_address, bin_mac->ether_addr_octet, ETH_ALEN);
                 g_object_set (sw,
                               "mac-address", hw_address,
                               NULL);
-                g_byte_array_unref (hw_address);
         }
         nm_connection_add_setting (c, (NMSetting *)sw);
 
@@ -1115,7 +1093,6 @@ start_shared_connection (NetDeviceWifi *device_wifi)
         nm_connection_add_setting (c, (NMSetting *)sip);
 
         g_object_set (sw, "ssid", ssid, NULL);
-        g_bytes_unref (ssid);
 
         sws = (NMSettingWirelessSecurity*) nm_setting_wireless_security_new ();
 
@@ -1146,8 +1123,6 @@ start_shared_connection (NetDeviceWifi *device_wifi)
                                                      cancellable,
                                                      activate_new_cb,
                                                      device_wifi);
-
-        g_object_unref (c);
 }
 
 static void
@@ -1479,18 +1454,15 @@ really_forgotten (GObject              *source_object,
                   GAsyncResult         *res,
                   gpointer              user_data)
 {
-        CcWifiConnectionList *list = user_data;
+        g_autoptr(CcWifiConnectionList) list = user_data;
         g_autoptr(GError) error = NULL;
 
         cc_wifi_connection_list_thaw (list);
-        g_object_unref (list);
 
-        if (!nm_remote_connection_delete_finish (NM_REMOTE_CONNECTION (source_object), res, &error)) {
+        if (!nm_remote_connection_delete_finish (NM_REMOTE_CONNECTION (source_object), res, &error))
                 g_warning ("failed to delete connection %s: %s",
                            nm_object_get_path (NM_OBJECT (source_object)),
                            error->message);
-                return;
-        }
 }
 
 static void
diff --git a/panels/network/net-proxy.c b/panels/network/net-proxy.c
index 759bf1844..26533057d 100644
--- a/panels/network/net-proxy.c
+++ b/panels/network/net-proxy.c
@@ -287,7 +287,10 @@ static void
 net_proxy_init (NetProxy *proxy)
 {
         GtkAdjustment *adjustment;
-        GSettings *settings_tmp;
+        g_autoptr(GSettings) http_settings = NULL;
+        g_autoptr(GSettings) https_settings = NULL;
+        g_autoptr(GSettings) ftp_settings = NULL;
+        g_autoptr(GSettings) socks_settings = NULL;
         ProxyMode value;
         GtkWidget *widget;
         g_autoptr(GError) error = NULL;
@@ -321,60 +324,56 @@ net_proxy_init (NetProxy *proxy)
                          G_SETTINGS_BIND_DEFAULT);
 
         /* bind the HTTP proxy values */
-        settings_tmp = g_settings_get_child (proxy->settings, "http");
+        http_settings = g_settings_get_child (proxy->settings, "http");
         widget = GTK_WIDGET (gtk_builder_get_object (proxy->builder,
                                                      "entry_proxy_http"));
-        g_settings_bind (settings_tmp, "host",
+        g_settings_bind (http_settings, "host",
                          widget, "text",
                          G_SETTINGS_BIND_DEFAULT);
         adjustment = GTK_ADJUSTMENT (gtk_builder_get_object (proxy->builder,
                                                              "adjustment_proxy_port_http"));
-        g_settings_bind (settings_tmp, "port",
+        g_settings_bind (http_settings, "port",
                          adjustment, "value",
                          G_SETTINGS_BIND_DEFAULT);
-        g_object_unref (settings_tmp);
 
         /* bind the HTTPS proxy values */
-        settings_tmp = g_settings_get_child (proxy->settings, "https");
+        https_settings = g_settings_get_child (proxy->settings, "https");
         widget = GTK_WIDGET (gtk_builder_get_object (proxy->builder,
                                                      "entry_proxy_https"));
-        g_settings_bind (settings_tmp, "host",
+        g_settings_bind (https_settings, "host",
                          widget, "text",
                          G_SETTINGS_BIND_DEFAULT);
         adjustment = GTK_ADJUSTMENT (gtk_builder_get_object (proxy->builder,
                                                              "adjustment_proxy_port_https"));
-        g_settings_bind (settings_tmp, "port",
+        g_settings_bind (https_settings, "port",
                          adjustment, "value",
                          G_SETTINGS_BIND_DEFAULT);
-        g_object_unref (settings_tmp);
 
         /* bind the FTP proxy values */
-        settings_tmp = g_settings_get_child (proxy->settings, "ftp");
+        ftp_settings = g_settings_get_child (proxy->settings, "ftp");
         widget = GTK_WIDGET (gtk_builder_get_object (proxy->builder,
                                                      "entry_proxy_ftp"));
-        g_settings_bind (settings_tmp, "host",
+        g_settings_bind (ftp_settings, "host",
                          widget, "text",
                          G_SETTINGS_BIND_DEFAULT);
         adjustment = GTK_ADJUSTMENT (gtk_builder_get_object (proxy->builder,
                                                              "adjustment_proxy_port_ftp"));
-        g_settings_bind (settings_tmp, "port",
+        g_settings_bind (ftp_settings, "port",
                          adjustment, "value",
                          G_SETTINGS_BIND_DEFAULT);
-        g_object_unref (settings_tmp);
 
         /* bind the SOCKS proxy values */
-        settings_tmp = g_settings_get_child (proxy->settings, "socks");
+        socks_settings = g_settings_get_child (proxy->settings, "socks");
         widget = GTK_WIDGET (gtk_builder_get_object (proxy->builder,
                                                      "entry_proxy_socks"));
-        g_settings_bind (settings_tmp, "host",
+        g_settings_bind (socks_settings, "host",
                          widget, "text",
                          G_SETTINGS_BIND_DEFAULT);
         adjustment = GTK_ADJUSTMENT (gtk_builder_get_object (proxy->builder,
                                                              "adjustment_proxy_port_socks"));
-        g_settings_bind (settings_tmp, "port",
+        g_settings_bind (socks_settings, "port",
                          adjustment, "value",
                          G_SETTINGS_BIND_DEFAULT);
-        g_object_unref (settings_tmp);
 
         /* bind the proxy ignore hosts */
         widget = GTK_WIDGET (gtk_builder_get_object (proxy->builder,
diff --git a/panels/network/network-dialogs.c b/panels/network/network-dialogs.c
index 250f4200d..c17e84991 100644
--- a/panels/network/network-dialogs.c
+++ b/panels/network/network-dialogs.c
@@ -100,7 +100,8 @@ wireless_dialog_response_cb (GtkDialog *foo,
 {
        NMAWifiDialog *dialog = NMA_WIFI_DIALOG (foo);
        WirelessDialogClosure *closure = user_data;
-       NMConnection *connection, *fuzzy_match = NULL;
+       g_autoptr(NMConnection) connection = NULL;
+       NMConnection *fuzzy_match = NULL;
        NMDevice *device;
        NMAccessPoint *ap;
        const GPtrArray *all;
@@ -164,9 +165,6 @@ wireless_dialog_response_cb (GtkDialog *foo,
                                                             NULL);
        }
 
-       /* Balance nma_wifi_dialog_get_connection() */
-       g_object_unref (connection);
-
 done:
        gtk_widget_hide (GTK_WIDGET (dialog));
        gtk_widget_destroy (GTK_WIDGET (dialog));
diff --git a/panels/network/wireless-security/eap-method-fast.c 
b/panels/network/wireless-security/eap-method-fast.c
index 98d5411a7..38734b61f 100644
--- a/panels/network/wireless-security/eap-method-fast.c
+++ b/panels/network/wireless-security/eap-method-fast.c
@@ -56,7 +56,7 @@ validate (EAPMethod *parent, GError **error)
        GtkWidget *widget;
        GtkTreeModel *model;
        GtkTreeIter iter;
-       EAPMethod *eap = NULL;
+       g_autoptr(EAPMethod) eap = NULL;
        const char *file;
        gboolean provisioning;
        gboolean valid = TRUE;
@@ -81,7 +81,6 @@ validate (EAPMethod *parent, GError **error)
        gtk_tree_model_get (model, &iter, I_METHOD_COLUMN, &eap, -1);
        g_assert (eap);
        valid = eap_method_validate (eap, valid ? error : NULL) && valid;
-       eap_method_unref (eap);
        return valid;
 }
 
@@ -92,7 +91,7 @@ add_to_size_group (EAPMethod *parent, GtkSizeGroup *group)
        GtkWidget *widget;
        GtkTreeModel *model;
        GtkTreeIter iter;
-       EAPMethod *eap;
+       g_autoptr(EAPMethod) eap = NULL;
 
        if (method->size_group)
                g_object_unref (method->size_group);
@@ -122,7 +121,6 @@ add_to_size_group (EAPMethod *parent, GtkSizeGroup *group)
        gtk_tree_model_get (model, &iter, I_METHOD_COLUMN, &eap, -1);
        g_assert (eap);
        eap_method_add_to_size_group (eap, group);
-       eap_method_unref (eap);
 }
 
 static void
@@ -132,7 +130,7 @@ fill_connection (EAPMethod *parent, NMConnection *connection, NMSettingSecretFla
        GtkWidget *widget;
        const char *text;
        char *filename;
-       EAPMethod *eap = NULL;
+       g_autoptr(EAPMethod) eap = NULL;
        GtkTreeModel *model;
        GtkTreeIter iter;
        gboolean enabled;
@@ -186,7 +184,6 @@ fill_connection (EAPMethod *parent, NMConnection *connection, NMSettingSecretFla
        g_assert (eap);
 
        eap_method_fill_connection (eap, connection, flags);
-       eap_method_unref (eap);
 }
 
 static void
@@ -195,7 +192,7 @@ inner_auth_combo_changed_cb (GtkWidget *combo, gpointer user_data)
        EAPMethod *parent = (EAPMethod *) user_data;
        EAPMethodFAST *method = (EAPMethodFAST *) parent;
        GtkWidget *vbox;
-       EAPMethod *eap = NULL;
+       g_autoptr(EAPMethod) eap = NULL;
        GList *elt, *children;
        GtkTreeModel *model;
        GtkTreeIter iter;
@@ -223,8 +220,6 @@ inner_auth_combo_changed_cb (GtkWidget *combo, gpointer user_data)
                eap_method_add_to_size_group (eap, method->size_group);
        gtk_container_add (GTK_CONTAINER (vbox), eap_widget);
 
-       eap_method_unref (eap);
-
        wireless_security_changed_cb (combo, method->sec_parent);
 }
 
@@ -236,10 +231,10 @@ inner_auth_combo_init (EAPMethodFAST *method,
 {
        EAPMethod *parent = (EAPMethod *) method;
        GtkWidget *combo;
-       GtkListStore *auth_model;
+       g_autoptr(GtkListStore) auth_model = NULL;
        GtkTreeIter iter;
-       EAPMethodSimple *em_gtc;
-       EAPMethodSimple *em_mschap_v2;
+       g_autoptr(EAPMethodSimple) em_gtc = NULL;
+       g_autoptr(EAPMethodSimple) em_mschap_v2 = NULL;
        guint32 active = 0;
        const char *phase2_auth = NULL;
        EAPMethodSimpleFlags simple_flags;
@@ -268,7 +263,6 @@ inner_auth_combo_init (EAPMethodFAST *method,
                            I_NAME_COLUMN, _("GTC"),
                            I_METHOD_COLUMN, em_gtc,
                            -1);
-       eap_method_unref (EAP_METHOD (em_gtc));
 
        /* Check for defaulting to GTC */
        if (phase2_auth && !strcasecmp (phase2_auth, "gtc"))
@@ -283,7 +277,6 @@ inner_auth_combo_init (EAPMethodFAST *method,
                            I_NAME_COLUMN, _("MSCHAPv2"),
                            I_METHOD_COLUMN, em_mschap_v2,
                            -1);
-       eap_method_unref (EAP_METHOD (em_mschap_v2));
 
        /* Check for defaulting to MSCHAPv2 */
        if (phase2_auth && !strcasecmp (phase2_auth, "mschapv2"))
@@ -293,7 +286,6 @@ inner_auth_combo_init (EAPMethodFAST *method,
        g_assert (combo);
 
        gtk_combo_box_set_model (GTK_COMBO_BOX (combo), GTK_TREE_MODEL (auth_model));
-       g_object_unref (G_OBJECT (auth_model));
        gtk_combo_box_set_active (GTK_COMBO_BOX (combo), active);
 
        g_signal_connect (G_OBJECT (combo), "changed",
diff --git a/panels/network/wireless-security/eap-method-fast.h 
b/panels/network/wireless-security/eap-method-fast.h
index 32b9a4b06..c19722058 100644
--- a/panels/network/wireless-security/eap-method-fast.h
+++ b/panels/network/wireless-security/eap-method-fast.h
@@ -32,5 +32,8 @@ EAPMethodFAST *eap_method_fast_new (WirelessSecurity *ws_parent,
                                     gboolean is_editor,
                                     gboolean secrets_only);
 
+static void eap_method_fast_unref (EAPMethodFAST *method) { eap_method_unref (EAP_METHOD (method)); }
+G_DEFINE_AUTOPTR_CLEANUP_FUNC (EAPMethodFAST, eap_method_fast_unref)
+
 #endif /* EAP_METHOD_FAST_H */
 
diff --git a/panels/network/wireless-security/eap-method-leap.h 
b/panels/network/wireless-security/eap-method-leap.h
index e3525ba1b..2d205d719 100644
--- a/panels/network/wireless-security/eap-method-leap.h
+++ b/panels/network/wireless-security/eap-method-leap.h
@@ -31,5 +31,8 @@ EAPMethodLEAP *eap_method_leap_new (WirelessSecurity *ws_parent,
                                     NMConnection *connection,
                                     gboolean secrets_only);
 
+static void eap_method_leap_unref (EAPMethodLEAP *method) { eap_method_unref (EAP_METHOD (method)); }
+G_DEFINE_AUTOPTR_CLEANUP_FUNC (EAPMethodLEAP, eap_method_leap_unref)
+
 #endif /* EAP_METHOD_LEAP_H */
 
diff --git a/panels/network/wireless-security/eap-method-peap.c 
b/panels/network/wireless-security/eap-method-peap.c
index 2296d9114..095c8de3b 100644
--- a/panels/network/wireless-security/eap-method-peap.c
+++ b/panels/network/wireless-security/eap-method-peap.c
@@ -55,7 +55,7 @@ validate (EAPMethod *parent, GError **error)
        GtkWidget *widget;
        GtkTreeModel *model;
        GtkTreeIter iter;
-       EAPMethod *eap = NULL;
+       g_autoptr(EAPMethod) eap = NULL;
        gboolean valid = FALSE;
        g_autoptr(GError) local_error = NULL;
 
@@ -76,7 +76,6 @@ validate (EAPMethod *parent, GError **error)
        gtk_tree_model_get (model, &iter, I_METHOD_COLUMN, &eap, -1);
        g_assert (eap);
        valid = eap_method_validate (eap, error);
-       eap_method_unref (eap);
        return valid;
 }
 
@@ -95,7 +94,7 @@ add_to_size_group (EAPMethod *parent, GtkSizeGroup *group)
        GtkWidget *widget;
        GtkTreeModel *model;
        GtkTreeIter iter;
-       EAPMethod *eap;
+       g_autoptr(EAPMethod) eap = NULL;
 
        if (method->size_group)
                g_object_unref (method->size_group);
@@ -129,7 +128,6 @@ add_to_size_group (EAPMethod *parent, GtkSizeGroup *group)
        gtk_tree_model_get (model, &iter, I_METHOD_COLUMN, &eap, -1);
        g_assert (eap);
        eap_method_add_to_size_group (eap, group);
-       eap_method_unref (eap);
 }
 
 static void
@@ -140,7 +138,7 @@ fill_connection (EAPMethod *parent, NMConnection *connection, NMSettingSecretFla
        GtkWidget *widget;
        const char *text;
        g_autofree gchar *filename = NULL;
-       EAPMethod *eap = NULL;
+       g_autoptr(EAPMethod) eap = NULL;
        GtkTreeModel *model;
        GtkTreeIter iter;
        int peapver_active = 0;
@@ -188,7 +186,6 @@ fill_connection (EAPMethod *parent, NMConnection *connection, NMSettingSecretFla
        g_assert (eap);
 
        eap_method_fill_connection (eap, connection, flags);
-       eap_method_unref (eap);
 }
 static void
 inner_auth_combo_changed_cb (GtkWidget *combo, gpointer user_data)
@@ -196,7 +193,7 @@ inner_auth_combo_changed_cb (GtkWidget *combo, gpointer user_data)
        EAPMethod *parent = (EAPMethod *) user_data;
        EAPMethodPEAP *method = (EAPMethodPEAP *) parent;
        GtkWidget *vbox;
-       EAPMethod *eap = NULL;
+       g_autoptr(EAPMethod) eap = NULL;
        GList *elt, *children;
        GtkTreeModel *model;
        GtkTreeIter iter;
@@ -223,8 +220,6 @@ inner_auth_combo_changed_cb (GtkWidget *combo, gpointer user_data)
                eap_method_add_to_size_group (eap, method->size_group);
        gtk_container_add (GTK_CONTAINER (vbox), eap_widget);
 
-       eap_method_unref (eap);
-
        wireless_security_changed_cb (combo, method->sec_parent);
 }
 
@@ -236,11 +231,11 @@ inner_auth_combo_init (EAPMethodPEAP *method,
 {
        EAPMethod *parent = (EAPMethod *) method;
        GtkWidget *combo;
-       GtkListStore *auth_model;
+       g_autoptr(GtkListStore) auth_model = NULL;
        GtkTreeIter iter;
-       EAPMethodSimple *em_mschap_v2;
-       EAPMethodSimple *em_md5;
-       EAPMethodSimple *em_gtc;
+       g_autoptr(EAPMethodSimple) em_mschap_v2 = NULL;
+       g_autoptr(EAPMethodSimple) em_md5 = NULL;
+       g_autoptr(EAPMethodSimple) em_gtc = NULL;
        guint32 active = 0;
        const char *phase2_auth = NULL;
        EAPMethodSimpleFlags simple_flags;
@@ -269,7 +264,6 @@ inner_auth_combo_init (EAPMethodPEAP *method,
                            I_NAME_COLUMN, _("MSCHAPv2"),
                            I_METHOD_COLUMN, em_mschap_v2,
                            -1);
-       eap_method_unref (EAP_METHOD (em_mschap_v2));
 
        /* Check for defaulting to MSCHAPv2 */
        if (phase2_auth && !strcasecmp (phase2_auth, "mschapv2"))
@@ -284,7 +278,6 @@ inner_auth_combo_init (EAPMethodPEAP *method,
                            I_NAME_COLUMN, _("MD5"),
                            I_METHOD_COLUMN, em_md5,
                            -1);
-       eap_method_unref (EAP_METHOD (em_md5));
 
        /* Check for defaulting to MD5 */
        if (phase2_auth && !strcasecmp (phase2_auth, "md5"))
@@ -299,7 +292,6 @@ inner_auth_combo_init (EAPMethodPEAP *method,
                            I_NAME_COLUMN, _("GTC"),
                            I_METHOD_COLUMN, em_gtc,
                            -1);
-       eap_method_unref (EAP_METHOD (em_gtc));
 
        /* Check for defaulting to GTC */
        if (phase2_auth && !strcasecmp (phase2_auth, "gtc"))
@@ -309,7 +301,6 @@ inner_auth_combo_init (EAPMethodPEAP *method,
        g_assert (combo);
 
        gtk_combo_box_set_model (GTK_COMBO_BOX (combo), GTK_TREE_MODEL (auth_model));
-       g_object_unref (G_OBJECT (auth_model));
        gtk_combo_box_set_active (GTK_COMBO_BOX (combo), active);
 
        g_signal_connect (G_OBJECT (combo), "changed",
diff --git a/panels/network/wireless-security/eap-method-peap.h 
b/panels/network/wireless-security/eap-method-peap.h
index 752306c93..45625fb93 100644
--- a/panels/network/wireless-security/eap-method-peap.h
+++ b/panels/network/wireless-security/eap-method-peap.h
@@ -32,5 +32,8 @@ EAPMethodPEAP *eap_method_peap_new (WirelessSecurity *ws_parent,
                                     gboolean is_editor,
                                     gboolean secrets_only);
 
+static void eap_method_peap_unref (EAPMethodPEAP *method) { eap_method_unref (EAP_METHOD (method)); }
+G_DEFINE_AUTOPTR_CLEANUP_FUNC (EAPMethodPEAP, eap_method_peap_unref)
+
 #endif /* EAP_METHOD_PEAP_H */
 
diff --git a/panels/network/wireless-security/eap-method-simple.h 
b/panels/network/wireless-security/eap-method-simple.h
index ecad120dd..8a2c3400e 100644
--- a/panels/network/wireless-security/eap-method-simple.h
+++ b/panels/network/wireless-security/eap-method-simple.h
@@ -59,5 +59,8 @@ EAPMethodSimple *eap_method_simple_new (WirelessSecurity *ws_parent,
                                         EAPMethodSimpleType type,
                                         EAPMethodSimpleFlags flags);
 
+static void eap_method_simple_unref (EAPMethodSimple *method) { eap_method_unref (EAP_METHOD (method)); }
+G_DEFINE_AUTOPTR_CLEANUP_FUNC (EAPMethodSimple, eap_method_simple_unref)
+
 #endif /* EAP_METHOD_SIMPLE_H */
 
diff --git a/panels/network/wireless-security/eap-method-tls.c 
b/panels/network/wireless-security/eap-method-tls.c
index a2b5c93b4..5a5b7e1cf 100644
--- a/panels/network/wireless-security/eap-method-tls.c
+++ b/panels/network/wireless-security/eap-method-tls.c
@@ -262,7 +262,7 @@ fill_connection (EAPMethod *parent, NMConnection *connection, NMSettingSecretFla
 static void
 private_key_picker_helper (EAPMethod *parent, const char *filename, gboolean changed)
 {
-       NMSetting8021x *setting;
+       g_autoptr(NMSetting8021x) setting = NULL;
        NMSetting8021xCKFormat cert_format = NM_SETTING_802_1X_CK_FORMAT_UNKNOWN;
        const char *password;
        GtkWidget *widget;
@@ -273,7 +273,6 @@ private_key_picker_helper (EAPMethod *parent, const char *filename, gboolean cha
 
        setting = (NMSetting8021x *) nm_setting_802_1x_new ();
        nm_setting_802_1x_set_private_key (setting, filename, password, NM_SETTING_802_1X_CK_SCHEME_PATH, 
&cert_format, NULL);
-       g_object_unref (setting);
 
        /* With PKCS#12, the client cert must be the same as the private key */
        widget = GTK_WIDGET (gtk_builder_get_object (parent->builder, "eap_tls_user_cert_button"));
diff --git a/panels/network/wireless-security/eap-method-tls.h 
b/panels/network/wireless-security/eap-method-tls.h
index 147a75f07..341580f09 100644
--- a/panels/network/wireless-security/eap-method-tls.h
+++ b/panels/network/wireless-security/eap-method-tls.h
@@ -32,5 +32,8 @@ EAPMethodTLS *eap_method_tls_new (WirelessSecurity *ws_parent,
                                   gboolean phase2,
                                   gboolean secrets_only);
 
+static void eap_method_tls_unref (EAPMethodTLS *method) { eap_method_unref (EAP_METHOD (method)); }
+G_DEFINE_AUTOPTR_CLEANUP_FUNC (EAPMethodTLS, eap_method_tls_unref)
+
 #endif /* EAP_METHOD_TLS_H */
 
diff --git a/panels/network/wireless-security/eap-method-ttls.c 
b/panels/network/wireless-security/eap-method-ttls.c
index 1332ef96c..2f6d6cb09 100644
--- a/panels/network/wireless-security/eap-method-ttls.c
+++ b/panels/network/wireless-security/eap-method-ttls.c
@@ -55,7 +55,7 @@ validate (EAPMethod *parent, GError **error)
        GtkWidget *widget;
        GtkTreeModel *model;
        GtkTreeIter iter;
-       EAPMethod *eap = NULL;
+       g_autoptr(EAPMethod) eap = NULL;
        gboolean valid = FALSE;
        g_autoptr(GError) local_error = NULL;
 
@@ -76,7 +76,6 @@ validate (EAPMethod *parent, GError **error)
        gtk_tree_model_get (model, &iter, I_METHOD_COLUMN, &eap, -1);
        g_assert (eap);
        valid = eap_method_validate (eap, error);
-       eap_method_unref (eap);
        return valid;
 }
 
@@ -95,7 +94,7 @@ add_to_size_group (EAPMethod *parent, GtkSizeGroup *group)
        GtkWidget *widget;
        GtkTreeModel *model;
        GtkTreeIter iter;
-       EAPMethod *eap;
+       g_autoptr(EAPMethod) eap = NULL;
 
        if (method->size_group)
                g_object_unref (method->size_group);
@@ -129,7 +128,6 @@ add_to_size_group (EAPMethod *parent, GtkSizeGroup *group)
        gtk_tree_model_get (model, &iter, I_METHOD_COLUMN, &eap, -1);
        g_assert (eap);
        eap_method_add_to_size_group (eap, group);
-       eap_method_unref (eap);
 }
 
 static void
@@ -140,7 +138,7 @@ fill_connection (EAPMethod *parent, NMConnection *connection, NMSettingSecretFla
        GtkWidget *widget;
        const char *text;
        g_autofree gchar *filename = NULL;
-       EAPMethod *eap = NULL;
+       g_autoptr(EAPMethod) eap = NULL;
        GtkTreeModel *model;
        GtkTreeIter iter;
        g_autoptr(GError) error = NULL;
@@ -179,7 +177,6 @@ fill_connection (EAPMethod *parent, NMConnection *connection, NMSettingSecretFla
        g_assert (eap);
 
        eap_method_fill_connection (eap, connection, flags);
-       eap_method_unref (eap);
 }
 
 static void
@@ -188,7 +185,7 @@ inner_auth_combo_changed_cb (GtkWidget *combo, gpointer user_data)
        EAPMethod *parent = (EAPMethod *) user_data;
        EAPMethodTTLS *method = (EAPMethodTTLS *) parent;
        GtkWidget *vbox;
-       EAPMethod *eap = NULL;
+       g_autoptr(EAPMethod) eap = NULL;
        GList *elt, *children;
        GtkTreeModel *model;
        GtkTreeIter iter;
@@ -216,8 +213,6 @@ inner_auth_combo_changed_cb (GtkWidget *combo, gpointer user_data)
                eap_method_add_to_size_group (eap, method->size_group);
        gtk_container_add (GTK_CONTAINER (vbox), eap_widget);
 
-       eap_method_unref (eap);
-
        wireless_security_changed_cb (combo, method->sec_parent);
 }
 
@@ -229,15 +224,15 @@ inner_auth_combo_init (EAPMethodTTLS *method,
 {
        EAPMethod *parent = (EAPMethod *) method;
        GtkWidget *combo;
-       GtkListStore *auth_model;
+       g_autoptr(GtkListStore) auth_model = NULL;
        GtkTreeIter iter;
-       EAPMethodSimple *em_pap;
-       EAPMethodSimple *em_mschap;
-       EAPMethodSimple *em_mschap_v2;
-       EAPMethodSimple *em_plain_mschap_v2;
-       EAPMethodSimple *em_chap;
-       EAPMethodSimple *em_md5;
-       EAPMethodSimple *em_gtc;
+       g_autoptr(EAPMethodSimple) em_pap = NULL;
+       g_autoptr(EAPMethodSimple) em_mschap = NULL;
+       g_autoptr(EAPMethodSimple) em_mschap_v2 = NULL;
+       g_autoptr(EAPMethodSimple) em_plain_mschap_v2 = NULL;
+       g_autoptr(EAPMethodSimple) em_chap = NULL;
+       g_autoptr(EAPMethodSimple) em_md5 = NULL;
+       g_autoptr(EAPMethodSimple) em_gtc = NULL;
        guint32 active = 0;
        const char *phase2_auth = NULL;
        EAPMethodSimpleFlags simple_flags;
@@ -266,7 +261,6 @@ inner_auth_combo_init (EAPMethodTTLS *method,
                            I_NAME_COLUMN, _("PAP"),
                            I_METHOD_COLUMN, em_pap,
                            -1);
-       eap_method_unref (EAP_METHOD (em_pap));
 
        /* Check for defaulting to PAP */
        if (phase2_auth && !strcasecmp (phase2_auth, "pap"))
@@ -281,7 +275,6 @@ inner_auth_combo_init (EAPMethodTTLS *method,
                            I_NAME_COLUMN, _("MSCHAP"),
                            I_METHOD_COLUMN, em_mschap,
                            -1);
-       eap_method_unref (EAP_METHOD (em_mschap));
 
        /* Check for defaulting to MSCHAP */
        if (phase2_auth && !strcasecmp (phase2_auth, "mschap"))
@@ -296,7 +289,6 @@ inner_auth_combo_init (EAPMethodTTLS *method,
                            I_NAME_COLUMN, _("MSCHAPv2"),
                            I_METHOD_COLUMN, em_mschap_v2,
                            -1);
-       eap_method_unref (EAP_METHOD (em_mschap_v2));
 
        /* Check for defaulting to MSCHAPv2 */
        if (phase2_auth && !strcasecmp (phase2_auth, "mschapv2") &&
@@ -312,7 +304,6 @@ inner_auth_combo_init (EAPMethodTTLS *method,
                            I_NAME_COLUMN, _("MSCHAPv2 (no EAP)"),
                            I_METHOD_COLUMN, em_plain_mschap_v2,
                            -1);
-       eap_method_unref (EAP_METHOD (em_plain_mschap_v2));
 
        /* Check for defaulting to plain MSCHAPv2 */
        if (phase2_auth && !strcasecmp (phase2_auth, "mschapv2") &&
@@ -328,7 +319,6 @@ inner_auth_combo_init (EAPMethodTTLS *method,
                            I_NAME_COLUMN, _("CHAP"),
                            I_METHOD_COLUMN, em_chap,
                            -1);
-       eap_method_unref (EAP_METHOD (em_chap));
 
        /* Check for defaulting to CHAP */
        if (phase2_auth && !strcasecmp (phase2_auth, "chap"))
@@ -343,7 +333,6 @@ inner_auth_combo_init (EAPMethodTTLS *method,
                            I_NAME_COLUMN, _("MD5"),
                            I_METHOD_COLUMN, em_md5,
                            -1);
-       eap_method_unref (EAP_METHOD (em_md5));
 
        /* Check for defaulting to MD5 */
        if (phase2_auth && !strcasecmp (phase2_auth, "md5"))
@@ -358,7 +347,6 @@ inner_auth_combo_init (EAPMethodTTLS *method,
                            I_NAME_COLUMN, _("GTC"),
                            I_METHOD_COLUMN, em_gtc,
                            -1);
-       eap_method_unref (EAP_METHOD (em_gtc));
 
        /* Check for defaulting to GTC */
        if (phase2_auth && !strcasecmp (phase2_auth, "gtc"))
@@ -368,7 +356,6 @@ inner_auth_combo_init (EAPMethodTTLS *method,
        g_assert (combo);
 
        gtk_combo_box_set_model (GTK_COMBO_BOX (combo), GTK_TREE_MODEL (auth_model));
-       g_object_unref (G_OBJECT (auth_model));
        gtk_combo_box_set_active (GTK_COMBO_BOX (combo), active);
 
        g_signal_connect (G_OBJECT (combo), "changed",
diff --git a/panels/network/wireless-security/eap-method-ttls.h 
b/panels/network/wireless-security/eap-method-ttls.h
index 16467f68b..836a6d9e6 100644
--- a/panels/network/wireless-security/eap-method-ttls.h
+++ b/panels/network/wireless-security/eap-method-ttls.h
@@ -32,5 +32,8 @@ EAPMethodTTLS *eap_method_ttls_new (WirelessSecurity *ws_parent,
                                     gboolean is_editor,
                                     gboolean secrets_only);
 
-#endif /* EAP_METHOD_TLS_H */
+static void eap_method_ttls_unref (EAPMethodTTLS *method) { eap_method_unref (EAP_METHOD (method)); }
+G_DEFINE_AUTOPTR_CLEANUP_FUNC (EAPMethodTTLS, eap_method_ttls_unref)
+
+#endif /* EAP_METHOD_TTLS_H */
 
diff --git a/panels/network/wireless-security/eap-method.c b/panels/network/wireless-security/eap-method.c
index 43091b103..4fca88af8 100644
--- a/panels/network/wireless-security/eap-method.c
+++ b/panels/network/wireless-security/eap-method.c
@@ -122,13 +122,11 @@ eap_method_phase2_update_secrets_helper (EAPMethod *method,
        model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo));
        if (gtk_tree_model_get_iter_first (model, &iter)) {
                do {
-                       EAPMethod *eap = NULL;
+                       g_autoptr(EAPMethod) eap = NULL;
 
                        gtk_tree_model_get (model, &iter, column, &eap, -1);
-                       if (eap) {
+                       if (eap)
                                eap_method_update_secrets (eap, connection);
-                               eap_method_unref (eap);
-                       }
                } while (gtk_tree_model_iter_next (model, &iter));
        }
 }
@@ -145,7 +143,7 @@ eap_method_init (gsize obj_size,
                  const char *default_field,
                  gboolean phase2)
 {
-       EAPMethod *method;
+       g_autoptr(EAPMethod) method = NULL;
        g_autoptr(GError) error = NULL;
 
        g_return_val_if_fail (obj_size > 0, NULL);
@@ -168,7 +166,6 @@ eap_method_init (gsize obj_size,
        if (!gtk_builder_add_from_resource (method->builder, ui_resource, &error)) {
                g_warning ("Couldn't load UI builder resource %s: %s",
                           ui_resource, error->message);
-               eap_method_unref (method);
                return NULL;
        }
 
@@ -176,14 +173,13 @@ eap_method_init (gsize obj_size,
        if (!method->ui_widget) {
                g_warning ("Couldn't load UI widget '%s' from UI file %s",
                           ui_widget_name, ui_resource);
-               eap_method_unref (method);
                return NULL;
        }
        g_object_ref_sink (method->ui_widget);
 
        method->destroy = destroy;
 
-       return method;
+       return g_steal_pointer (&method);
 }
 
 
@@ -227,7 +223,7 @@ eap_method_validate_filepicker (GtkBuilder *builder,
 {
        GtkWidget *widget;
        g_autofree gchar *filename = NULL;
-       NMSetting8021x *setting;
+       g_autoptr(NMSetting8021x) setting = NULL;
        gboolean success = TRUE;
 
        if (item_type == TYPE_PRIVATE_KEY) {
@@ -266,8 +262,6 @@ eap_method_validate_filepicker (GtkBuilder *builder,
        } else
                g_warning ("%s: invalid item type %d.", __func__, item_type);
 
-       g_object_unref (setting);
-
 out:
        if (!success && error && !*error)
                g_set_error_literal (error, NMA_ERROR, NMA_ERROR_GENERIC, _("unspecified error validating 
eap-method file"));
@@ -624,7 +618,7 @@ void
 eap_method_ca_cert_ignore_save (NMConnection *connection)
 {
        NMSetting8021x *s_8021x;
-       GSettings *settings;
+       g_autoptr(GSettings) settings = NULL;
        gboolean ignore = FALSE, phase2_ignore = FALSE;
 
        g_return_if_fail (connection);
@@ -641,7 +635,6 @@ eap_method_ca_cert_ignore_save (NMConnection *connection)
 
        g_settings_set_boolean (settings, IGNORE_CA_CERT_TAG, ignore);
        g_settings_set_boolean (settings, IGNORE_PHASE2_CA_CERT_TAG, phase2_ignore);
-       g_object_unref (settings);
 }
 
 /**
@@ -654,7 +647,7 @@ eap_method_ca_cert_ignore_save (NMConnection *connection)
 void
 eap_method_ca_cert_ignore_load (NMConnection *connection)
 {
-       GSettings *settings;
+       g_autoptr(GSettings) settings = NULL;
        NMSetting8021x *s_8021x;
        gboolean ignore, phase2_ignore;
 
@@ -677,6 +670,5 @@ eap_method_ca_cert_ignore_load (NMConnection *connection)
        g_object_set_data (G_OBJECT (s_8021x),
                           IGNORE_PHASE2_CA_CERT_TAG,
                           GUINT_TO_POINTER (phase2_ignore));
-       g_object_unref (settings);
 }
 
diff --git a/panels/network/wireless-security/eap-method.h b/panels/network/wireless-security/eap-method.h
index fd2655c4f..0bb71634c 100644
--- a/panels/network/wireless-security/eap-method.h
+++ b/panels/network/wireless-security/eap-method.h
@@ -130,4 +130,6 @@ gboolean eap_method_ca_cert_ignore_get (EAPMethod *method, NMConnection *connect
 void eap_method_ca_cert_ignore_save (NMConnection *connection);
 void eap_method_ca_cert_ignore_load (NMConnection *connection);
 
+G_DEFINE_AUTOPTR_CLEANUP_FUNC (EAPMethod, eap_method_unref)
+
 #endif /* EAP_METHOD_H */
diff --git a/panels/network/wireless-security/wireless-security.c 
b/panels/network/wireless-security/wireless-security.c
index 75bc889c1..ec93db69c 100644
--- a/panels/network/wireless-security/wireless-security.c
+++ b/panels/network/wireless-security/wireless-security.c
@@ -165,7 +165,7 @@ wireless_security_init (gsize obj_size,
                         const char *ui_widget_name,
                         const char *default_field)
 {
-       WirelessSecurity *sec;
+       g_autoptr(WirelessSecurity) sec = NULL;
        g_autoptr(GError) error = NULL;
 
        g_return_val_if_fail (obj_size > 0, NULL);
@@ -190,7 +190,6 @@ wireless_security_init (gsize obj_size,
        if (!gtk_builder_add_from_resource (sec->builder, ui_resource, &error)) {
                g_warning ("Couldn't load UI builder resource %s: %s",
                           ui_resource, error->message);
-               wireless_security_unref (sec);
                return NULL;
        }
 
@@ -198,7 +197,6 @@ wireless_security_init (gsize obj_size,
        if (!sec->ui_widget) {
                g_warning ("Couldn't load UI widget '%s' from UI file %s",
                           ui_widget_name, ui_resource);
-               wireless_security_unref (sec);
                return NULL;
        }
        g_object_ref_sink (sec->ui_widget);
@@ -207,7 +205,7 @@ wireless_security_init (gsize obj_size,
        sec->adhoc_compatible = TRUE;
        sec->hotspot_compatible = TRUE;
 
-       return sec;
+       return g_steal_pointer (&sec);
 }
 
 gboolean
@@ -297,7 +295,7 @@ ws_802_1x_add_to_size_group (WirelessSecurity *sec,
        GtkWidget *widget;
        GtkTreeModel *model;
        GtkTreeIter iter;
-       EAPMethod *eap;
+       g_autoptr(EAPMethod) eap = NULL;
 
        widget = GTK_WIDGET (gtk_builder_get_object (sec->builder, label_name));
        g_assert (widget);
@@ -311,7 +309,6 @@ ws_802_1x_add_to_size_group (WirelessSecurity *sec,
        gtk_tree_model_get (model, &iter, AUTH_METHOD_COLUMN, &eap, -1);
        g_assert (eap);
        eap_method_add_to_size_group (eap, size_group);
-       eap_method_unref (eap);
 }
 
 gboolean
@@ -320,7 +317,7 @@ ws_802_1x_validate (WirelessSecurity *sec, const char *combo_name, GError **erro
        GtkWidget *widget;
        GtkTreeModel *model;
        GtkTreeIter iter;
-       EAPMethod *eap = NULL;
+       g_autoptr(EAPMethod) eap = NULL;
        gboolean valid = FALSE;
 
        widget = GTK_WIDGET (gtk_builder_get_object (sec->builder, combo_name));
@@ -331,7 +328,6 @@ ws_802_1x_validate (WirelessSecurity *sec, const char *combo_name, GError **erro
        gtk_tree_model_get (model, &iter, AUTH_METHOD_COLUMN, &eap, -1);
        g_assert (eap);
        valid = eap_method_validate (eap, error);
-       eap_method_unref (eap);
        return valid;
 }
 
@@ -342,7 +338,7 @@ ws_802_1x_auth_combo_changed (GtkWidget *combo,
                               GtkSizeGroup *size_group)
 {
        GtkWidget *vbox;
-       EAPMethod *eap = NULL;
+       g_autoptr(EAPMethod) eap = NULL;
        GList *elt, *children;
        GtkTreeModel *model;
        GtkTreeIter iter;
@@ -377,8 +373,6 @@ ws_802_1x_auth_combo_changed (GtkWidget *combo,
                        gtk_widget_grab_focus (eap_default_widget);
        }
 
-       eap_method_unref (eap);
-
        wireless_security_changed_cb (combo, WIRELESS_SECURITY (sec));
 }
 
@@ -392,15 +386,13 @@ ws_802_1x_auth_combo_init (WirelessSecurity *sec,
                            gboolean secrets_only)
 {
        GtkWidget *combo, *widget;
-       GtkListStore *auth_model;
+       g_autoptr(GtkListStore) auth_model = NULL;
        GtkTreeIter iter;
-       EAPMethodSimple *em_md5;
-       EAPMethodTLS *em_tls;
-       EAPMethodLEAP *em_leap;
-       EAPMethodSimple *em_pwd;
-       EAPMethodFAST *em_fast;
-       EAPMethodTTLS *em_ttls;
-       EAPMethodPEAP *em_peap;
+       g_autoptr(EAPMethodTLS) em_tls = NULL;
+       g_autoptr(EAPMethodSimple) em_pwd = NULL;
+       g_autoptr(EAPMethodFAST) em_fast = NULL;
+       g_autoptr(EAPMethodTTLS) em_ttls = NULL;
+       g_autoptr(EAPMethodPEAP) em_peap = NULL;
        const char *default_method = NULL, *ctype = NULL;
        int active = -1, item = 0;
        gboolean wired = FALSE;
@@ -434,13 +426,14 @@ ws_802_1x_auth_combo_init (WirelessSecurity *sec,
                simple_flags |= EAP_METHOD_SIMPLE_FLAG_SECRETS_ONLY;
 
        if (wired) {
+               g_autoptr(EAPMethodSimple) em_md5 = NULL;
+
                em_md5 = eap_method_simple_new (sec, connection, EAP_METHOD_SIMPLE_TYPE_MD5, simple_flags);
                gtk_list_store_append (auth_model, &iter);
                gtk_list_store_set (auth_model, &iter,
                                        AUTH_NAME_COLUMN, _("MD5"),
                                        AUTH_METHOD_COLUMN, em_md5,
                                        -1);
-               eap_method_unref (EAP_METHOD (em_md5));
                if (default_method && (active < 0) && !strcmp (default_method, "md5"))
                        active = item;
                item++;
@@ -452,19 +445,19 @@ ws_802_1x_auth_combo_init (WirelessSecurity *sec,
                            AUTH_NAME_COLUMN, _("TLS"),
                            AUTH_METHOD_COLUMN, em_tls,
                            -1);
-       eap_method_unref (EAP_METHOD (em_tls));
        if (default_method && (active < 0) && !strcmp (default_method, "tls"))
                active = item;
        item++;
 
        if (!wired) {
+               g_autoptr(EAPMethodLEAP) em_leap = NULL;
+
                em_leap = eap_method_leap_new (sec, connection, secrets_only);
                gtk_list_store_append (auth_model, &iter);
                gtk_list_store_set (auth_model, &iter,
                                    AUTH_NAME_COLUMN, _("LEAP"),
                                    AUTH_METHOD_COLUMN, em_leap,
                                    -1);
-               eap_method_unref (EAP_METHOD (em_leap));
                if (default_method && (active < 0) && !strcmp (default_method, "leap"))
                        active = item;
                item++;
@@ -476,7 +469,6 @@ ws_802_1x_auth_combo_init (WirelessSecurity *sec,
                            AUTH_NAME_COLUMN, _("PWD"),
                            AUTH_METHOD_COLUMN, em_pwd,
                            -1);
-       eap_method_unref (EAP_METHOD (em_pwd));
        if (default_method && (active < 0) && !strcmp (default_method, "pwd"))
                active = item;
        item++;
@@ -487,7 +479,6 @@ ws_802_1x_auth_combo_init (WirelessSecurity *sec,
                            AUTH_NAME_COLUMN, _("FAST"),
                            AUTH_METHOD_COLUMN, em_fast,
                            -1);
-       eap_method_unref (EAP_METHOD (em_fast));
        if (default_method && (active < 0) && !strcmp (default_method, "fast"))
                active = item;
        item++;
@@ -498,7 +489,6 @@ ws_802_1x_auth_combo_init (WirelessSecurity *sec,
                            AUTH_NAME_COLUMN, _("Tunneled TLS"),
                            AUTH_METHOD_COLUMN, em_ttls,
                            -1);
-       eap_method_unref (EAP_METHOD (em_ttls));
        if (default_method && (active < 0) && !strcmp (default_method, "ttls"))
                active = item;
        item++;
@@ -509,7 +499,6 @@ ws_802_1x_auth_combo_init (WirelessSecurity *sec,
                            AUTH_NAME_COLUMN, _("Protected EAP (PEAP)"),
                            AUTH_METHOD_COLUMN, em_peap,
                            -1);
-       eap_method_unref (EAP_METHOD (em_peap));
        if (default_method && (active < 0) && !strcmp (default_method, "peap"))
                active = item;
        item++;
@@ -518,7 +507,6 @@ ws_802_1x_auth_combo_init (WirelessSecurity *sec,
        g_assert (combo);
 
        gtk_combo_box_set_model (GTK_COMBO_BOX (combo), GTK_TREE_MODEL (auth_model));
-       g_object_unref (G_OBJECT (auth_model));
        gtk_combo_box_set_active (GTK_COMBO_BOX (combo), active < 0 ? 0 : (guint32) active);
 
        g_signal_connect (G_OBJECT (combo), "changed", auth_combo_changed_cb, sec);
@@ -541,7 +529,7 @@ ws_802_1x_fill_connection (WirelessSecurity *sec,
        NMSettingWirelessSecurity *s_wireless_sec;
        NMSetting8021x *s_8021x;
        NMSettingSecretFlags secret_flags = NM_SETTING_SECRET_FLAG_NONE;
-       EAPMethod *eap = NULL;
+       g_autoptr(EAPMethod) eap = NULL;
        GtkTreeModel *model;
        GtkTreeIter iter;
 
@@ -568,7 +556,6 @@ ws_802_1x_fill_connection (WirelessSecurity *sec,
        nm_connection_add_setting (connection, (NMSetting *) s_8021x);
 
        eap_method_fill_connection (eap, connection, secret_flags);
-       eap_method_unref (eap);
 }
 
 void
@@ -577,7 +564,6 @@ ws_802_1x_update_secrets (WirelessSecurity *sec,
                           NMConnection *connection)
 {
        GtkWidget *widget;
-       EAPMethod *eap = NULL;
        GtkTreeModel *model;
        GtkTreeIter iter;
 
@@ -592,11 +578,11 @@ ws_802_1x_update_secrets (WirelessSecurity *sec,
        /* Let each EAP method try to update its secrets */
        if (gtk_tree_model_get_iter_first (model, &iter)) {
                do {
+                       g_autoptr(EAPMethod) eap = NULL;
+
                        gtk_tree_model_get (model, &iter, AUTH_METHOD_COLUMN, &eap, -1);
-                       if (eap) {
+                       if (eap)
                                eap_method_update_secrets (eap, connection);
-                               eap_method_unref (eap);
-                       }
                } while (gtk_tree_model_iter_next (model, &iter));
        }
 }
diff --git a/panels/network/wireless-security/wireless-security.h 
b/panels/network/wireless-security/wireless-security.h
index 975e750f6..aaeb685cd 100644
--- a/panels/network/wireless-security/wireless-security.h
+++ b/panels/network/wireless-security/wireless-security.h
@@ -150,5 +150,7 @@ void ws_802_1x_update_secrets (WirelessSecurity *sec,
                                const char *combo_name,
                                NMConnection *connection);
 
+G_DEFINE_AUTOPTR_CLEANUP_FUNC (WirelessSecurity, wireless_security_unref)
+
 #endif /* WIRELESS_SECURITY_H */
 


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