From 2ae83e116bc1ce2c02548940e276c294c91c5da7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Javier=20Jard=C3=B3n?= Date: Mon, 2 Jan 2012 16:10:35 +0100 Subject: [PATCH] glib/*: Use g_list_free_full() --- glib/gbookmarkfile.c | 38 ++++++-------------------------------- glib/gkeyfile.c | 10 ++-------- glib/goption.c | 3 +-- glib/gregex.c | 15 +++++---------- 4 files changed, 14 insertions(+), 52 deletions(-) diff --git a/glib/gbookmarkfile.c b/glib/gbookmarkfile.c index 0306bc2..4709cdf 100644 --- a/glib/gbookmarkfile.c +++ b/glib/gbookmarkfile.c @@ -359,21 +359,8 @@ bookmark_metadata_free (BookmarkMetadata *metadata) g_free (metadata->mime_type); - if (metadata->groups) - { - g_list_foreach (metadata->groups, - (GFunc) g_free, - NULL); - g_list_free (metadata->groups); - } - - if (metadata->applications) - { - g_list_foreach (metadata->applications, - (GFunc) bookmark_app_info_free, - NULL); - g_list_free (metadata->applications); - } + g_list_free_full (metadata->groups, g_free); + g_list_free_full (metadata->applications, (GDestroyNotify) bookmark_app_info_free); g_hash_table_destroy (metadata->apps_by_name); @@ -687,15 +674,8 @@ g_bookmark_file_clear (GBookmarkFile *bookmark) g_free (bookmark->title); g_free (bookmark->description); - if (bookmark->items) - { - g_list_foreach (bookmark->items, - (GFunc) bookmark_item_free, - NULL); - g_list_free (bookmark->items); - - bookmark->items = NULL; - } + g_list_free_full (bookmark->items, (GDestroyNotify) bookmark_item_free); + bookmark->items = NULL; if (bookmark->items_by_uri) { @@ -2933,14 +2913,8 @@ g_bookmark_file_set_groups (GBookmarkFile *bookmark, if (!item->metadata) item->metadata = bookmark_metadata_new (); - if (item->metadata->groups != NULL) - { - g_list_foreach (item->metadata->groups, - (GFunc) g_free, - NULL); - g_list_free (item->metadata->groups); - item->metadata->groups = NULL; - } + g_list_free_full (item->metadata->groups, g_free); + item->metadata->groups = NULL; if (groups) { diff --git a/glib/gkeyfile.c b/glib/gkeyfile.c index 713721f..8de05a2 100644 --- a/glib/gkeyfile.c +++ b/glib/gkeyfile.c @@ -3197,14 +3197,8 @@ g_key_file_set_top_comment (GKeyFile *key_file, /* Note all keys must be comments at the top of * the file, so we can just free it all. */ - if (group->key_value_pairs != NULL) - { - g_list_foreach (group->key_value_pairs, - (GFunc) g_key_file_key_value_pair_free, - NULL); - g_list_free (group->key_value_pairs); - group->key_value_pairs = NULL; - } + g_list_free_full (group->key_value_pairs, (GDestroyNotify) g_key_file_key_value_pair_free); + group->key_value_pairs = NULL; if (comment == NULL) return TRUE; diff --git a/glib/goption.c b/glib/goption.c index 799ea09..c65e84c 100644 --- a/glib/goption.c +++ b/glib/goption.c @@ -356,8 +356,7 @@ void g_option_context_free (GOptionContext *context) { g_return_if_fail (context != NULL); - g_list_foreach (context->groups, (GFunc)g_option_group_free, NULL); - g_list_free (context->groups); + g_list_free_full (context->groups, (GDestroyNotify) g_option_group_free); if (context->main_group) g_option_group_free (context->main_group); diff --git a/glib/gregex.c b/glib/gregex.c index f8b8701..ffffda7 100644 --- a/glib/gregex.c +++ b/glib/gregex.c @@ -835,8 +835,7 @@ g_match_info_expand_references (const GMatchInfo *match_info, result = g_string_sized_new (strlen (string_to_expand)); interpolate_replacement (match_info, result, list); - g_list_foreach (list, (GFunc)free_interpolation_data, NULL); - g_list_free (list); + g_list_free_full (list, (GDestroyNotify) free_interpolation_data); return g_string_free (result, FALSE); } @@ -2062,8 +2061,7 @@ g_regex_split_full (const GRegex *regex, if (tmp_error != NULL) { g_propagate_error (error, tmp_error); - g_list_foreach (list, (GFunc)g_free, NULL); - g_list_free (list); + g_list_free_full (list, g_free); match_info->pos = -1; return NULL; } @@ -2385,8 +2383,7 @@ split_replacement (const gchar *replacement, start = p = expand_escape (replacement, p, data, error); if (p == NULL) { - g_list_foreach (list, (GFunc)free_interpolation_data, NULL); - g_list_free (list); + g_list_free_full (list, (GDestroyNotify) free_interpolation_data); free_interpolation_data (data); return NULL; @@ -2617,8 +2614,7 @@ g_regex_replace (const GRegex *regex, if (tmp_error != NULL) g_propagate_error (error, tmp_error); - g_list_foreach (list, (GFunc)free_interpolation_data, NULL); - g_list_free (list); + g_list_free_full (list, (GDestroyNotify) free_interpolation_data); return result; } @@ -2827,8 +2823,7 @@ g_regex_check_replacement (const gchar *replacement, if (has_references) *has_references = interpolation_list_needs_match (list); - g_list_foreach (list, (GFunc) free_interpolation_data, NULL); - g_list_free (list); + g_list_free_full (list, (GDestroyNotify) free_interpolation_data); return TRUE; } -- 2.7.4