aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2016-04-21 08:48:59 +0200
committerMarc André Tanner <mat@brain-dump.org>2016-04-21 08:49:33 +0200
commit793f1e212bb08d2edba172cd32d0ef8cc43a1aeb (patch)
tree7aa1626594a448b81a2f7ee60b5ca8210912d6a8
parent348eb8074fe0d314ca08fa39f4584019621e3f92 (diff)
downloadvis-793f1e212bb08d2edba172cd32d0ef8cc43a1aeb.tar.gz
vis-793f1e212bb08d2edba172cd32d0ef8cc43a1aeb.tar.xz
map: add map_free_full utility function
-rw-r--r--map.c14
-rw-r--r--map.h2
2 files changed, 16 insertions, 0 deletions
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