[gnome-terminal] profile: Use the cleanup attribute to clean up



commit 11a556e484d4a9eb2303fdf36d858cfd70205249
Author: Christian Persch <chpe gnome org>
Date:   Mon Oct 21 17:55:46 2013 +0200

    profile: Use the cleanup attribute to clean up

 src/terminal-settings-list.c |   69 +++++++++++++++++------------------------
 1 files changed, 29 insertions(+), 40 deletions(-)
---
diff --git a/src/terminal-settings-list.c b/src/terminal-settings-list.c
index 7c7667c..f17bb1d 100644
--- a/src/terminal-settings-list.c
+++ b/src/terminal-settings-list.c
@@ -26,6 +26,7 @@
 #include "terminal-type-builtins.h"
 #include "terminal-schemas.h"
 #include "terminal-debug.h"
+#include "terminal-libgsystem.h"
 
 struct _TerminalSettingsList {
   GSettings parent;
@@ -212,16 +213,15 @@ list_map_func (GVariant *value,
                gpointer user_data)
 {
   TerminalSettingsList *list = user_data;
-  char **entries;
+  gs_strfreev char **entries;
 
   entries = strv_sort (g_variant_dup_strv (value, NULL));
 
   if (validate_list (list, entries)) {
-    *result = entries;
+    gs_transfer_out_value(result, &entries);
     return TRUE;
   }
 
-  g_strfreev (entries);
   return FALSE;
 }
 
@@ -237,7 +237,7 @@ terminal_settings_list_ref_child_internal (TerminalSettingsList *list,
                                            const char *uuid)
 {
   GSettings *child;
-  char *path;
+  gs_free char *path = NULL;
 
   if (strv_find (list->uuids, uuid) == -1)
     return NULL;
@@ -252,7 +252,6 @@ terminal_settings_list_ref_child_internal (TerminalSettingsList *list,
   path = path_new (list, uuid);
   child = g_settings_new_with_path (list->child_schema_id, path);
   g_hash_table_insert (list->children, g_strdup (uuid), child /* adopted */);
-  g_free (path);
 
  done:
   return g_object_ref (child);
@@ -263,11 +262,11 @@ clone_child (TerminalSettingsList *list,
              const char *uuid)
 {
   char *new_uuid;
-  char *path, *new_path;
-  char **keys, *key;
+  gs_free char *path;
+  gs_free char *new_path;
+  char **keys;
   guint i;
-  GVariant *value;
-  DConfClient *client;
+  gs_unref_object DConfClient *client;
 #ifndef HAVE_DCONF_1_2
   DConfChangeset *changeset;
 #endif
@@ -289,29 +288,29 @@ clone_child (TerminalSettingsList *list,
 
   /* FIXME: this is beyond ugly. Need API on GSettingsSchema to list all the keys! */
   {
-    GSettings *dummy = g_settings_new_with_path (list->child_schema_id, "/foo");
+    gs_unref_object GSettings *dummy = g_settings_new_with_path (list->child_schema_id, "/foo");
     keys = g_settings_list_keys (dummy);
-    g_object_unref (dummy);
   }
 
   for (i = 0; keys[i]; i++) {
-    key = g_strconcat (path, keys[i], NULL);
+    gs_free char *rkey;
+    gs_unref_variant GVariant *value;
+
+    rkey = g_strconcat (path, keys[i], NULL);
 #ifdef HAVE_DCONF_1_2
-    value = dconf_client_read_no_default (client, key);
+    value = dconf_client_read_no_default (client, rkey);
 #else
-    value = dconf_client_read (client, key);
+    value = dconf_client_read (client, rkey);
 #endif
-    g_free (key);
 
     if (value) {
-      key = g_strconcat (new_path, keys[i], NULL);
+      gs_free char *wkey;
+      wkey = g_strconcat (new_path, keys[i], NULL);
 #ifdef HAVE_DCONF_1_2
-      dconf_client_write (client, key, value, NULL, NULL, NULL);
+      dconf_client_write (client, wkey, value, NULL, NULL, NULL);
 #else
-      dconf_changeset_set (changeset, key, value);
+      dconf_changeset_set (changeset, wkey, value);
 #endif
-      g_free (key);
-      g_variant_unref (value);
     }
   }
 
@@ -319,9 +318,6 @@ clone_child (TerminalSettingsList *list,
   dconf_client_change_sync (client, changeset, NULL, NULL, NULL);
   dconf_changeset_unref (changeset);
 #endif
-  g_object_unref (client);
-  g_free (path);
-  g_free (new_path);
 
   return new_uuid;
 }
@@ -331,7 +327,7 @@ terminal_settings_list_add_child_internal (TerminalSettingsList *list,
                                            const char *uuid)
 {
   char *new_uuid;
-  char **new_uuids;
+  gs_strfreev char **new_uuids;
 
   if (uuid)
     new_uuid = clone_child (list, uuid);
@@ -344,7 +340,6 @@ terminal_settings_list_add_child_internal (TerminalSettingsList *list,
   new_uuids = strv_dupv_insert (list->uuids, new_uuid);
   g_settings_set_strv (&list->parent, TERMINAL_SETTINGS_LIST_LIST_KEY,
                        (const char * const *) new_uuids);
-  g_strfreev (new_uuids);
 
   return new_uuid;
 }
@@ -353,8 +348,9 @@ static void
 terminal_settings_list_remove_child_internal (TerminalSettingsList *list,
                                               const char *uuid)
 {
-  char **new_uuids, *path;
-  DConfClient *client;
+  gs_strfreev char **new_uuids;
+  gs_free char *path = NULL;
+  gs_unref_object DConfClient *client = NULL;
 
   _terminal_debug_print (TERMINAL_DEBUG_SETTINGS_LIST,
                          "%s UUID %s\n", G_STRFUNC, uuid);
@@ -362,13 +358,10 @@ terminal_settings_list_remove_child_internal (TerminalSettingsList *list,
   new_uuids = strv_dupv_remove (list->uuids, uuid);
 
   if ((new_uuids == NULL || new_uuids[0] == NULL) &&
-      (list->flags & TERMINAL_SETTINGS_LIST_FLAG_ALLOW_EMPTY) == 0) {
-    g_strfreev (new_uuids);
+      (list->flags & TERMINAL_SETTINGS_LIST_FLAG_ALLOW_EMPTY) == 0)
     return;
-  }
 
   g_settings_set_strv (&list->parent, TERMINAL_SETTINGS_LIST_LIST_KEY, (const char * const *) new_uuids);
-  g_strfreev (new_uuids);
 
   if (list->default_uuid != NULL &&
       g_str_equal (list->default_uuid, uuid))
@@ -384,9 +377,6 @@ terminal_settings_list_remove_child_internal (TerminalSettingsList *list,
   client = dconf_client_new ();
   dconf_client_write_sync (client, path, NULL, NULL, NULL, NULL);
 #endif
-  g_object_unref (client);
-
-  g_free (path);
 }
 
 static void
@@ -764,7 +754,7 @@ terminal_settings_list_ref_children (TerminalSettingsList *list)
 GSettings *
 terminal_settings_list_ref_default_child (TerminalSettingsList *list)
 {
-  char *uuid;
+  gs_free char *uuid;
 
   g_return_val_if_fail (TERMINAL_IS_SETTINGS_LIST (list), NULL);
 
@@ -841,7 +831,8 @@ char *
 terminal_settings_list_dup_uuid_from_child (TerminalSettingsList *list,
                                             GSettings *child)
 {
-  char *path, *p;
+  gs_free char *path;
+  char *p;
 
   g_return_val_if_fail (TERMINAL_IS_SETTINGS_LIST (list), NULL);
 
@@ -853,11 +844,9 @@ terminal_settings_list_dup_uuid_from_child (TerminalSettingsList *list,
   p++;
   g_return_val_if_fail (strlen (p) == 37, NULL);
   p[36] = '\0';
-  g_return_val_if_fail (terminal_settings_list_valid_uuid (p), NULL);
+  g_assert (terminal_settings_list_valid_uuid (p));
 
-  p = g_strdup (p);
-  g_free (path);
-  return p;
+  return g_strdup (p);
 }
 
 /**


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