[gnome-control-center] applications: Use g_autofree for strings



commit 6691c4dfd3f0cba250a9bd65a8ad519e6564a618
Author: Robert Ancell <robert ancell canonical com>
Date:   Fri Sep 27 11:57:51 2019 +1200

    applications: Use g_autofree for strings

 panels/applications/cc-applications-panel.c | 49 +++++++++++++----------------
 1 file changed, 22 insertions(+), 27 deletions(-)
---
diff --git a/panels/applications/cc-applications-panel.c b/panels/applications/cc-applications-panel.c
index 1cc476093..998f2bee5 100644
--- a/panels/applications/cc-applications-panel.c
+++ b/panels/applications/cc-applications-panel.c
@@ -547,8 +547,12 @@ add_static_permissions (CcApplicationsPanel *self,
                         const gchar         *app_id)
 {
   g_autoptr(GKeyFile) keyfile = NULL;
+  g_auto(GStrv) sockets = NULL;
+  g_auto(GStrv) devices = NULL;
+  g_auto(GStrv) shared = NULL;
+  g_auto(GStrv) filesystems = NULL;
   gchar **strv;
-  gchar *str;
+  g_autofree gchar *str = NULL;
   gint added = 0;
   g_autofree gchar *text = NULL;
   
@@ -556,40 +560,35 @@ add_static_permissions (CcApplicationsPanel *self,
   if (keyfile == NULL)
     return FALSE;
 
-  strv = g_key_file_get_string_list (keyfile, "Context", "sockets", NULL, NULL);
-  if (strv && g_strv_contains ((const gchar * const*)strv, "system-bus"))
+  sockets = g_key_file_get_string_list (keyfile, "Context", "sockets", NULL, NULL);
+  if (sockets && g_strv_contains ((const gchar * const*)sockets, "system-bus"))
     added += add_static_permission_row (self, _("System Bus"), _("Full access"));
-  if (strv && g_strv_contains ((const gchar * const*)strv, "session-bus"))
+  if (sockets && g_strv_contains ((const gchar * const*)sockets, "session-bus"))
     added += add_static_permission_row (self, _("Session Bus"), _("Full access"));
-  g_strfreev (strv);
 
-  strv = g_key_file_get_string_list (keyfile, "Context", "devices", NULL, NULL);
-  if (strv && g_strv_contains ((const gchar * const*)strv, "all"))
+  devices = g_key_file_get_string_list (keyfile, "Context", "devices", NULL, NULL);
+  if (devices && g_strv_contains ((const gchar * const*)devices, "all"))
     added += add_static_permission_row (self, _("Devices"), _("Full access to /dev"));
-  g_strfreev (strv);
 
-  strv = g_key_file_get_string_list (keyfile, "Context", "shared", NULL, NULL);
-  if (strv && g_strv_contains ((const gchar * const*)strv, "network"))
+  shared = g_key_file_get_string_list (keyfile, "Context", "shared", NULL, NULL);
+  if (shared && g_strv_contains ((const gchar * const*)shared, "network"))
     added += add_static_permission_row (self, _("Network"), _("Has network access"));
-  g_strfreev (strv);
 
-  strv = g_key_file_get_string_list (keyfile, "Context", "filesystems", NULL, NULL);
-  if (strv && (g_strv_contains ((const gchar * const *)strv, "home") ||
-               g_strv_contains ((const gchar * const *)strv, "home:rw")))
+  filesystems = g_key_file_get_string_list (keyfile, "Context", "filesystems", NULL, NULL);
+  if (filesystems && (g_strv_contains ((const gchar * const *)filesystems, "home") ||
+               g_strv_contains ((const gchar * const *)filesystems, "home:rw")))
     added += add_static_permission_row (self, _("Home"), _("Full access"));
-  else if (strv && g_strv_contains ((const gchar * const *)strv, "home:ro"))
+  else if (filesystems && g_strv_contains ((const gchar * const *)filesystems, "home:ro"))
     added += add_static_permission_row (self, _("Home"), _("Read-only"));
-  if (strv && (g_strv_contains ((const gchar * const *)strv, "host") ||
-               g_strv_contains ((const gchar * const *)strv, "host:rw")))
+  if (filesystems && (g_strv_contains ((const gchar * const *)filesystems, "host") ||
+               g_strv_contains ((const gchar * const *)filesystems, "host:rw")))
     added += add_static_permission_row (self, _("File System"), _("Full access"));
-  else if (strv && g_strv_contains ((const gchar * const *)strv, "host:ro"))
+  else if (filesystems && g_strv_contains ((const gchar * const *)filesystems, "host:ro"))
     added += add_static_permission_row (self, _("File System"), _("Read-only"));
-  g_strfreev (strv);
 
   str = g_key_file_get_string (keyfile, "Session Bus Policy", "ca.desrt.dconf", NULL);
   if (str && g_str_equal (str, "talk"))
     added += add_static_permission_row (self, _("Settings"), _("Can change settings"));
-  g_free (str);
 
   gtk_widget_set_visible (self->builtin, added > 0);
 
@@ -1168,23 +1167,19 @@ update_handler_sections (CcApplicationsPanel *self,
   gtk_widget_set_sensitive (self->handler_reset, FALSE);
   for (i = 0; types[i]; i++)
     {
-      gchar *ctype = g_content_type_from_mime_type (types[i]);
+      g_autofree gchar *ctype = g_content_type_from_mime_type (types[i]);
 
       if (g_hash_table_contains (hash, ctype))
-        {
-          g_free (ctype);
-          continue;
-        }
+        continue;
 
       if (!app_info_recommended_for (info, ctype))
         {
           gtk_widget_set_sensitive (self->handler_reset, TRUE);
-          g_free (ctype);
           continue;
         }
 
-      g_hash_table_add (hash, ctype);
       add_handler_row (self, ctype);
+      g_hash_table_add (hash, g_steal_pointer (&ctype));
     }
 }
 


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