diff --git a/clutter/clutter/clutter-binding-pool.c b/clutter/clutter/clutter-binding-pool.c index f0ec29a72..60144baf9 100644 --- a/clutter/clutter/clutter-binding-pool.c +++ b/clutter/clutter/clutter-binding-pool.c @@ -235,8 +235,7 @@ clutter_binding_pool_finalize (GObject *gobject) g_hash_table_destroy (pool->entries_hash); - g_slist_foreach (pool->entries, (GFunc) binding_entry_free, NULL); - g_slist_free (pool->entries); + g_slist_free_full (pool->entries, (GDestroyNotify) binding_entry_free); G_OBJECT_CLASS (clutter_binding_pool_parent_class)->finalize (gobject); } diff --git a/clutter/clutter/clutter-master-clock-default.c b/clutter/clutter/clutter-master-clock-default.c index 0647c3a7f..6779eb70b 100644 --- a/clutter/clutter/clutter-master-clock-default.c +++ b/clutter/clutter/clutter-master-clock-default.c @@ -412,8 +412,7 @@ master_clock_advance_timelines (ClutterMasterClockDefault *master_clock) for (l = timelines; l != NULL; l = l->next) _clutter_timeline_do_tick (l->data, master_clock->cur_tick / 1000); - g_slist_foreach (timelines, (GFunc) g_object_unref, NULL); - g_slist_free (timelines); + g_slist_free_full (timelines, g_object_unref); #ifdef CLUTTER_ENABLE_DEBUG if (_clutter_diagnostic_enabled ()) @@ -574,8 +573,7 @@ clutter_clock_dispatch (GSource *source, master_clock_reschedule_stage_updates (master_clock, stages); - g_slist_foreach (stages, (GFunc) g_object_unref, NULL); - g_slist_free (stages); + g_slist_free_full (stages, g_object_unref); master_clock->prev_tick = master_clock->cur_tick; diff --git a/clutter/clutter/clutter-path.c b/clutter/clutter/clutter-path.c index 6ea433bb5..d80ddbeb6 100644 --- a/clutter/clutter/clutter-path.c +++ b/clutter/clutter/clutter-path.c @@ -295,8 +295,7 @@ clutter_path_clear (ClutterPath *path) { ClutterPathPrivate *priv = path->priv; - g_slist_foreach (priv->nodes, (GFunc) clutter_path_node_full_free, NULL); - g_slist_free (priv->nodes); + g_slist_free_full (priv->nodes, (GDestroyNotify) clutter_path_node_full_free); priv->nodes = priv->nodes_tail = NULL; priv->nodes_dirty = TRUE; @@ -659,8 +658,7 @@ clutter_path_parse_description (const gchar *p, return TRUE; fail: - g_slist_foreach (nodes, (GFunc) clutter_path_node_full_free, NULL); - g_slist_free (nodes); + g_slist_free_full (nodes, (GDestroyNotify) clutter_path_node_full_free); return FALSE; } diff --git a/clutter/clutter/clutter-script.c b/clutter/clutter/clutter-script.c index a62fb4ca9..516b515e1 100644 --- a/clutter/clutter/clutter-script.c +++ b/clutter/clutter/clutter-script.c @@ -843,8 +843,7 @@ clutter_script_unmerge_objects (ClutterScript *script, for (l = data.ids; l != NULL; l = l->next) g_hash_table_remove (priv->objects, l->data); - g_slist_foreach (data.ids, (GFunc) g_free, NULL); - g_slist_free (data.ids); + g_slist_free_full (data.ids, g_free); clutter_script_ensure_objects (script); } diff --git a/clutter/clutter/clutter-stage-manager.c b/clutter/clutter/clutter-stage-manager.c index 7955a895f..31b3a2be1 100644 --- a/clutter/clutter/clutter-stage-manager.c +++ b/clutter/clutter/clutter-stage-manager.c @@ -89,8 +89,8 @@ clutter_stage_manager_dispose (GObject *gobject) stage_manager = CLUTTER_STAGE_MANAGER (gobject); - g_slist_foreach (stage_manager->stages, (GFunc) clutter_actor_destroy, NULL); - g_slist_free (stage_manager->stages); + g_slist_free_full (stage_manager->stages, + (GDestroyNotify) clutter_actor_destroy); stage_manager->stages = NULL; G_OBJECT_CLASS (clutter_stage_manager_parent_class)->dispose (gobject); diff --git a/clutter/tests/conform/timeline.c b/clutter/tests/conform/timeline.c index 55822ff40..96bd09277 100644 --- a/clutter/tests/conform/timeline.c +++ b/clutter/tests/conform/timeline.c @@ -38,8 +38,7 @@ timeline_data_init (TimelineData *data, int timeline_num) static void timeline_data_destroy (TimelineData *data) { - g_slist_foreach (data->markers_hit, (GFunc) g_free, NULL); - g_slist_free (data->markers_hit); + g_slist_free_full (data->markers_hit, g_free); } static void diff --git a/cogl/cogl-pango/cogl-pango-display-list.c b/cogl/cogl-pango/cogl-pango-display-list.c index 6a99a4c1b..72e381761 100644 --- a/cogl/cogl-pango/cogl-pango-display-list.c +++ b/cogl/cogl-pango/cogl-pango-display-list.c @@ -483,8 +483,8 @@ _cogl_pango_display_list_node_free (CoglPangoDisplayListNode *node) void _cogl_pango_display_list_clear (CoglPangoDisplayList *dl) { - g_slist_foreach (dl->nodes, (GFunc) _cogl_pango_display_list_node_free, NULL); - g_slist_free (dl->nodes); + g_slist_free_full (dl->nodes, (GDestroyNotify) + _cogl_pango_display_list_node_free); dl->nodes = NULL; dl->last_node = NULL; } diff --git a/cogl/cogl/cogl-renderer.c b/cogl/cogl/cogl-renderer.c index 7b39e439d..035c68418 100644 --- a/cogl/cogl/cogl-renderer.c +++ b/cogl/cogl/cogl-renderer.c @@ -194,10 +194,8 @@ _cogl_renderer_free (CoglRenderer *renderer) if (renderer->libgl_module) g_module_close (renderer->libgl_module); - g_slist_foreach (renderer->event_filters, - (GFunc) native_filter_closure_free, - NULL); - g_slist_free (renderer->event_filters); + g_slist_free_full (renderer->event_filters, + (GDestroyNotify) native_filter_closure_free); g_array_free (renderer->poll_fds, TRUE); diff --git a/cogl/cogl/deprecated/cogl-program.c b/cogl/cogl/deprecated/cogl-program.c index 1cd2f7a50..56fd895ba 100644 --- a/cogl/cogl/deprecated/cogl-program.c +++ b/cogl/cogl/deprecated/cogl-program.c @@ -59,10 +59,8 @@ _cogl_program_free (CoglProgram *program) _COGL_GET_CONTEXT (ctx, NO_RETVAL); - /* Unref all of the attached shaders */ - g_slist_foreach (program->attached_shaders, (GFunc) cogl_handle_unref, NULL); - /* Destroy the list */ - g_slist_free (program->attached_shaders); + /* Unref all of the attached shaders and destroy the list */ + g_slist_free_full (program->attached_shaders, cogl_handle_unref); for (i = 0; i < program->custom_uniforms->len; i++) { diff --git a/src/core/edge-resistance.c b/src/core/edge-resistance.c index 4f24c6de7..65ff47408 100644 --- a/src/core/edge-resistance.c +++ b/src/core/edge-resistance.c @@ -1157,13 +1157,7 @@ compute_resistance_and_snapping_edges (MetaDisplay *display) g_list_free (stacked_windows); /* Free the memory used by the obscuring windows/docks lists */ g_slist_free (window_stacking); - /* FIXME: Shouldn't there be a helper function to make this one line of code - * to free a list instead of four ugly ones? - */ - g_slist_foreach (obscuring_windows, - (void (*)(gpointer,gpointer))&g_free, /* ew, for ugly */ - NULL); - g_slist_free (obscuring_windows); + g_slist_free_full (obscuring_windows, g_free); /* Sort the list. FIXME: Should I bother with this sorting? I just * sort again later in cache_edges() anyway... diff --git a/src/core/startup-notification.c b/src/core/startup-notification.c index 4cd51aca6..1d4446439 100644 --- a/src/core/startup-notification.c +++ b/src/core/startup-notification.c @@ -575,8 +575,7 @@ meta_startup_notification_finalize (GObject *object) if (sn->startup_sequence_timeout) g_source_remove (sn->startup_sequence_timeout); - g_slist_foreach (sn->startup_sequences, (GFunc) g_object_unref, NULL); - g_slist_free (sn->startup_sequences); + g_slist_free_full (sn->startup_sequences, g_object_unref); sn->startup_sequences = NULL; G_OBJECT_CLASS (meta_startup_notification_parent_class)->finalize (object); diff --git a/src/core/util.c b/src/core/util.c index 57b73747d..e5503139b 100644 --- a/src/core/util.c +++ b/src/core/util.c @@ -249,10 +249,7 @@ utf8_fputs (const char *str, void meta_free_gslist_and_elements (GSList *list_to_deep_free) { - g_slist_foreach (list_to_deep_free, - (void (*)(gpointer,gpointer))&g_free, /* ew, for ugly */ - NULL); - g_slist_free (list_to_deep_free); + g_slist_free_full (list_to_deep_free, g_free); } #ifdef WITH_VERBOSE_MODE diff --git a/src/core/workspace.c b/src/core/workspace.c index 5dbc86324..b4fd836c9 100644 --- a/src/core/workspace.c +++ b/src/core/workspace.c @@ -52,8 +52,6 @@ void meta_workspace_queue_calc_showing (MetaWorkspace *workspace); static void focus_ancestor_or_top_window (MetaWorkspace *workspace, MetaWindow *not_this_one, guint32 timestamp); -static void free_this (gpointer candidate, - gpointer dummy); G_DEFINE_TYPE (MetaWorkspace, meta_workspace, G_TYPE_OBJECT); @@ -265,13 +263,6 @@ meta_workspace_new (MetaWorkspaceManager *workspace_manager) return workspace; } -/* Foreach function for workspace_free_struts() */ -static void -free_this (gpointer candidate, gpointer dummy) -{ - g_free (candidate); -} - /** * workspace_free_all_struts: * @workspace: The workspace. @@ -284,8 +275,7 @@ workspace_free_all_struts (MetaWorkspace *workspace) if (workspace->all_struts == NULL) return; - g_slist_foreach (workspace->all_struts, free_this, NULL); - g_slist_free (workspace->all_struts); + g_slist_free_full (workspace->all_struts, g_free); workspace->all_struts = NULL; } @@ -301,8 +291,7 @@ workspace_free_builtin_struts (MetaWorkspace *workspace) if (workspace->builtin_struts == NULL) return; - g_slist_foreach (workspace->builtin_struts, free_this, NULL); - g_slist_free (workspace->builtin_struts); + g_slist_free_full (workspace->builtin_struts, g_free); workspace->builtin_struts = NULL; } diff --git a/src/tests/boxes-tests.c b/src/tests/boxes-tests.c index 4f648a344..7b5bb3e7a 100644 --- a/src/tests/boxes-tests.c +++ b/src/tests/boxes-tests.c @@ -221,13 +221,7 @@ test_basic_fitting (void) static void free_strut_list (GSList *struts) { - GSList *tmp = struts; - while (tmp) - { - g_free (tmp->data); - tmp = tmp->next; - } - g_slist_free (struts); + g_slist_free_full (struts, g_free); } static GSList*