diff options
author | Robert Ancell <robert.ancell@canonical.com> | 2018-01-23 16:03:19 +1300 |
---|---|---|
committer | Robert Ancell <robert.ancell@canonical.com> | 2018-01-23 16:03:19 +1300 |
commit | 8bd73df60c4d05a3c8849d77c0ca0f3844f6522a (patch) | |
tree | ffc50dfcadd997c841ea41e5b03c289aa04fa19e | |
parent | 1e62c99f416ce0695e388b5ad57e790223254d1b (diff) | |
download | gnome-control-center-wip/rancell/keyboard-g-auto.tar.gz |
keyboard: Use g_auto for variableswip/rancell/keyboard-g-auto
-rw-r--r-- | panels/keyboard/cc-keyboard-manager.c | 24 | ||||
-rw-r--r-- | panels/keyboard/cc-keyboard-option.c | 4 | ||||
-rw-r--r-- | panels/keyboard/cc-keyboard-panel.c | 17 | ||||
-rw-r--r-- | panels/keyboard/cc-keyboard-shortcut-editor.c | 4 | ||||
-rw-r--r-- | panels/keyboard/keyboard-shortcuts.c | 35 | ||||
-rw-r--r-- | panels/keyboard/wm-common.c | 10 |
6 files changed, 31 insertions, 63 deletions
diff --git a/panels/keyboard/cc-keyboard-manager.c b/panels/keyboard/cc-keyboard-manager.c index 82f646058..549503b02 100644 --- a/panels/keyboard/cc-keyboard-manager.c +++ b/panels/keyboard/cc-keyboard-manager.c @@ -228,7 +228,8 @@ add_shortcuts (CcKeyboardManager *self) { BindingGroupType group; GPtrArray *keys; - gchar *id, *title; + g_autofree gchar *id = NULL; + g_autofree gchar *title = NULL; gint i; gtk_tree_model_get (sections_model, @@ -272,9 +273,6 @@ add_shortcuts (CcKeyboardManager *self) } can_continue = gtk_tree_model_iter_next (sections_model, §ions_iter); - - g_free (title); - g_free (id); } } @@ -431,11 +429,10 @@ append_sections_from_file (CcKeyboardManager *self, keys = (KeyListEntry *) g_array_free (keylist->entries, FALSE); if (keylist->package) { - char *localedir; + g_autofree gchar *localedir - NULL; localedir = g_build_filename (datadir, "locale", NULL); bindtextdomain (keylist->package, localedir); - g_free (localedir); title = dgettext (keylist->package, keylist->name); } else { @@ -471,7 +468,7 @@ append_sections_from_file (CcKeyboardManager *self, static void append_sections_from_gsettings (CcKeyboardManager *self) { - char **custom_paths; + g_auto(GStrv) custom_paths = NULL; GArray *entries; KeyListEntry key = { 0, 0, 0, 0, 0, 0, 0 }; int i; @@ -491,7 +488,6 @@ append_sections_from_gsettings (CcKeyboardManager *self) else g_free (key.name); } - g_strfreev (custom_paths); if (entries->len > 0) { @@ -565,21 +561,18 @@ reload_sections (CcKeyboardManager *self) data_dirs = g_get_system_data_dirs (); for (i = 0; data_dirs[i] != NULL; i++) { - char *dir_path; + g_autofree gchar *dir_path = NULL; const gchar *name; dir_path = g_build_filename (data_dirs[i], "gnome-control-center", "keybindings", NULL); dir = g_dir_open (dir_path, 0, NULL); if (!dir) - { - g_free (dir_path); continue; - } for (name = g_dir_read_name (dir) ; name ; name = g_dir_read_name (dir)) { - gchar *path; + g_autofree gchar *path = NULL; if (g_str_has_suffix (name, ".xml") == FALSE) continue; @@ -593,10 +586,8 @@ reload_sections (CcKeyboardManager *self) g_hash_table_insert (loaded_files, g_strdup (name), GINT_TO_POINTER (1)); path = g_build_filename (dir_path, name, NULL); append_sections_from_file (self, path, data_dirs[i], wm_keybindings); - g_free (path); } - g_free (dir_path); g_dir_close (dir); } @@ -754,7 +745,7 @@ CcKeyboardItem* cc_keyboard_manager_create_custom_shortcut (CcKeyboardManager *self) { CcKeyboardItem *item; - gchar *settings_path; + g_autofree gchar *settings_path = NULL; g_return_val_if_fail (CC_IS_KEYBOARD_MANAGER (self), NULL); @@ -762,7 +753,6 @@ cc_keyboard_manager_create_custom_shortcut (CcKeyboardManager *self) settings_path = find_free_settings_path (self->binding_settings); cc_keyboard_item_load_from_gsettings_path (item, settings_path, TRUE); - g_free (settings_path); item->model = GTK_TREE_MODEL (self->shortcuts_model); item->group = BINDING_GROUP_USER; diff --git a/panels/keyboard/cc-keyboard-option.c b/panels/keyboard/cc-keyboard-option.c index e7b92630f..d608f37fb 100644 --- a/panels/keyboard/cc-keyboard-option.c +++ b/panels/keyboard/cc-keyboard-option.c @@ -442,7 +442,7 @@ void cc_keyboard_option_set_selection (CcKeyboardOption *self, GtkTreeIter *iter) { - gchar *new_value = NULL; + g_autofree gchar *new_value = NULL; g_return_if_fail (CC_IS_KEYBOARD_OPTION (self)); @@ -465,8 +465,6 @@ cc_keyboard_option_set_selection (CcKeyboardOption *self, g_settings_set_strv (input_sources_settings, XKB_OPTIONS_KEY, (const gchar * const *) current_xkb_options); - - g_free (new_value); } void diff --git a/panels/keyboard/cc-keyboard-panel.c b/panels/keyboard/cc-keyboard-panel.c index 02f250a4a..df856fabf 100644 --- a/panels/keyboard/cc-keyboard-panel.c +++ b/panels/keyboard/cc-keyboard-panel.c @@ -118,13 +118,11 @@ transform_binding_to_accel (GBinding *binding, /* Embolden the label when the shortcut is modified */ if (!cc_keyboard_item_is_value_default (item)) { - gchar *tmp; + g_autofree gchar *tmp = NULL; tmp = convert_keysym_state_to_string (combo); accelerator = g_strdup_printf ("<b>%s</b>", tmp); - - g_free (tmp); } else { @@ -507,7 +505,7 @@ header_function (GtkListBoxRow *row, if (add_header) { GtkWidget *box, *label; - gchar *markup; + g_autofree gchar *markup = NULL; box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6); gtk_widget_set_margin_top (box, before ? 18 : 6); @@ -528,8 +526,6 @@ header_function (GtkListBoxRow *row, gtk_list_box_row_set_header (row, box); gtk_widget_show_all (box); - - g_free (markup); } else { @@ -545,8 +541,9 @@ filter_function (GtkListBoxRow *row, CcKeyboardItem *item; RowData *data; gboolean retval; - gchar *search, *name; - gchar **terms; + g_autofree gchar *search = NULL; + g_autofree gchar *name = NULL; + g_auto(GStrv) terms = NULL; guint i; if (gtk_entry_get_text_length (GTK_ENTRY (self->search_entry)) == 0) @@ -569,10 +566,6 @@ filter_function (GtkListBoxRow *row, break; } - g_free (search); - g_free (name); - g_strfreev (terms); - return retval; } diff --git a/panels/keyboard/cc-keyboard-shortcut-editor.c b/panels/keyboard/cc-keyboard-shortcut-editor.c index 24eacdf57..9e83eaba4 100644 --- a/panels/keyboard/cc-keyboard-shortcut-editor.c +++ b/panels/keyboard/cc-keyboard-shortcut-editor.c @@ -153,7 +153,7 @@ apply_custom_item_fields (CcKeyboardShortcutEditor *self, if (self->edited) { CcKeyCombo *combo = item->primary_combo; - gchar *binding; + g_autofree gchar *binding = NULL; combo->keycode = self->custom_combo->keycode; combo->keyval = self->custom_combo->keyval; @@ -168,8 +168,6 @@ apply_custom_item_fields (CcKeyboardShortcutEditor *self, combo->mask); g_object_set (G_OBJECT (item), "binding", binding, NULL); - - g_free (binding); } /* Set the keyboard shortcut name and command for custom entries */ diff --git a/panels/keyboard/keyboard-shortcuts.c b/panels/keyboard/keyboard-shortcuts.c index bebc50a33..856c18ec7 100644 --- a/panels/keyboard/keyboard-shortcuts.c +++ b/panels/keyboard/keyboard-shortcuts.c @@ -33,10 +33,10 @@ static char * replace_pictures_folder (const char *description) { - GRegex *pictures_regex; + g_autoptr(GRegex) pictures_regex = NULL; const char *path; - char *dirname; - char *ret; + g_autofree gchar *dirname = NULL; + g_autofree gchar *ret = NULL; if (description == NULL) return NULL; @@ -50,13 +50,10 @@ replace_pictures_folder (const char *description) ret = g_regex_replace (pictures_regex, description, -1, 0, dirname, 0, NULL); - g_regex_unref (pictures_regex); - g_free (dirname); - if (ret == NULL) return g_strdup (description); - return ret; + return g_steal_pointer (&ret); } static void @@ -313,8 +310,8 @@ is_valid_accel (CcKeyCombo *combo) gchar* find_free_settings_path (GSettings *settings) { - char **used_names; - char *dir = NULL; + g_auto(GStrv) used_names = NULL; + g_autofree gchar *dir = NULL; int i, num, n_names; used_names = g_settings_get_strv (settings, "custom-keybindings"); @@ -322,7 +319,7 @@ find_free_settings_path (GSettings *settings) for (num = 0; dir == NULL; num++) { - char *tmp; + g_autofree gchar *tmp = NULL; gboolean found = FALSE; tmp = g_strdup_printf ("%s/custom%d/", CUSTOM_KEYS_BASENAME, num); @@ -330,13 +327,10 @@ find_free_settings_path (GSettings *settings) found = strcmp (used_names[i], tmp) == 0; if (!found) - dir = tmp; - else - g_free (tmp); + dir = g_steal_pointer (&tmp); } - g_strfreev (used_names); - return dir; + return g_steal_pointer (&dir); } static gboolean @@ -381,12 +375,12 @@ KeyList* parse_keylist_from_file (const gchar *path) { KeyList *keylist; - GError *err = NULL; - char *buf; + g_autoptr(GError) err = NULL; + g_autofree gchar *buf = NULL; gsize buf_len; guint i; - GMarkupParseContext *ctx; + g_autoptr(GMarkupParseContext) ctx = NULL; GMarkupParser parser = { parse_start_tag, NULL, NULL, NULL, NULL }; /* Parse file */ @@ -400,7 +394,6 @@ parse_keylist_from_file (const gchar *path) if (!g_markup_parse_context_parse (ctx, buf, buf_len, &err)) { g_warning ("Failed to parse '%s': '%s'", path, err->message); - g_error_free (err); g_free (keylist->name); g_free (keylist->package); g_free (keylist->wm_name); @@ -410,10 +403,8 @@ parse_keylist_from_file (const gchar *path) g_array_free (keylist->entries, TRUE); g_free (keylist); - keylist = NULL; + return NULL; } - g_markup_parse_context_free (ctx); - g_free (buf); return keylist; } diff --git a/panels/keyboard/wm-common.c b/panels/keyboard/wm-common.c index c7270d139..2c6c15393 100644 --- a/panels/keyboard/wm-common.c +++ b/panels/keyboard/wm-common.c @@ -76,8 +76,8 @@ char** wm_common_get_current_keybindings (void) { Atom keybindings_atom = XInternAtom (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), "_GNOME_WM_KEYBINDINGS", False); - char *keybindings = wm_common_get_window_manager_property (keybindings_atom); - char **results; + g_autofree char *keybindings = wm_common_get_window_manager_property (keybindings_atom); + g_auto(GStrv) results = NULL; if (keybindings) { @@ -85,21 +85,19 @@ wm_common_get_current_keybindings (void) results = g_strsplit(keybindings, ",", -1); for (p = results; *p; p++) g_strstrip (*p); - g_free (keybindings); } else { Atom wm_atom = XInternAtom (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), "_NET_WM_NAME", False); - char *wm_name = wm_common_get_window_manager_property (wm_atom); + g_autofee char *wm_name = wm_common_get_window_manager_property (wm_atom); char *to_copy[] = { NULL, NULL }; to_copy[0] = wm_name ? wm_name : WM_COMMON_UNKNOWN; results = g_strdupv (to_copy); - g_free (wm_name); } - return results; + return g_steal_pointer (&results); } static void |