diff options
author | Ryan Lortie <desrt@desrt.ca> | 2009-10-16 12:19:06 +0200 |
---|---|---|
committer | Ryan Lortie <desrt@desrt.ca> | 2010-10-28 11:20:57 -0400 |
commit | 7c184df292f7552423fa7931c843b2f1949c1455 (patch) | |
tree | 06b73239ee5a4718e5620a64627c5fda1271aaac /glib/gslist.c | |
parent | 4baad1acbff936284c5367afdb4494cf081ee394 (diff) | |
download | glib-7c184df292f7552423fa7931c843b2f1949c1455.tar.gz |
Bug 158725 - free linked list with data
Add some helpers for freeing a linked list along with its elements by
providing a GDestroyNotify to call on each of them.
Add a test.
Based on a patch from Cosimo Cecchi.
Diffstat (limited to 'glib/gslist.c')
-rw-r--r-- | glib/gslist.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/glib/gslist.c b/glib/gslist.c index dfbd35440..f6581a8fa 100644 --- a/glib/gslist.c +++ b/glib/gslist.c @@ -187,6 +187,24 @@ g_slist_free_1 (GSList *list) } /** + * g_slist_free_full: + * @list: a pointer to a #GSList + * @free_func: the function to be called to free each element's data + * + * Convenience method, which frees all the memory used by a #GSList, and + * calls the specified destroy function on every element's data. + * + * Since: 2.28 + **/ +void +g_slist_free_full (GSList *list, + GDestroyNotify free_func) +{ + g_slist_foreach (list, (GFunc) free_func, NULL); + g_slist_free (list); +} + +/** * g_slist_append: * @list: a #GSList * @data: the data for the new element |