From 793f1e212bb08d2edba172cd32d0ef8cc43a1aeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Thu, 21 Apr 2016 08:48:59 +0200 Subject: map: add map_free_full utility function --- map.c | 14 ++++++++++++++ map.h | 2 ++ 2 files changed, 16 insertions(+) diff --git a/map.c b/map.c index 48590b3..10d39de 100644 --- 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 index 0540fab..816e537 100644 --- 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 -- cgit v1.2.3