vis
a vi-like editor based on Plan 9's structural regular expressions
git clone https://9o.is/git/vis.git
commit ba88dfe9043188a8a20b9a43ed2b6b3f1644daa5 parent dae1c6770f6be69aa2054f8d727b4f476e52369e Author: Marc André Tanner <mat@brain-dump.org> Date: Thu, 21 Apr 2016 08:48:59 +0200 map: add map_free_full utility function Diffstat:
| M | map.c | | | 14 | ++++++++++++++ |
| M | map.h | | | 2 | ++ |
2 files changed, 16 insertions(+), 0 deletions(-)
diff --git a/map.c b/map.c @@ -324,3 +324,17 @@ void map_free(Map *map) map_clear(map); free(map); } + +static bool free_elem(const char *key, void *value, void *data) +{ + free(value); + return true; +} + +void map_free_full(Map *map) +{ + if (!map) + return; + map_iterate(map, free_elem, NULL); + map_free(map); +} diff --git a/map.h b/map.h @@ -35,5 +35,7 @@ bool map_empty(const Map*); void map_clear(Map*); /* Release all memory associated with this map */ void map_free(Map*); +/* Call free(3) for every pointer stored in the map, then free the map itself */ +void map_free_full(Map*); #endif