]> err.no Git - systemd/commitdiff
set: introduce set_free_free()
authorLennart Poettering <lennart@poettering.net>
Tue, 15 Jun 2010 00:45:26 +0000 (02:45 +0200)
committerLennart Poettering <lennart@poettering.net>
Tue, 15 Jun 2010 00:45:26 +0000 (02:45 +0200)
src/load-fragment.c
src/set.c
src/set.h
src/unit.c

index 5f5e37397b222c4354be13ef5eb02bc527eb0bb2..b679fab479a3e29a280a4c6a6bd604fa25780db8 100644 (file)
@@ -1483,7 +1483,6 @@ static int load_from_path(Unit *u, const char *path) {
 #undef EXEC_CONTEXT_CONFIG_ITEMS
 
         const char *sections[3];
-        char *k;
         int r;
         Set *symlink_names;
         FILE *f = NULL;
@@ -1581,10 +1580,7 @@ static int load_from_path(Unit *u, const char *path) {
         r = 0;
 
 finish:
-        while ((k = set_steal_first(symlink_names)))
-                free(k);
-
-        set_free(symlink_names);
+        set_free_free(symlink_names);
         free(filename);
 
         if (f)
index efd20db536bda44c6b3e22c6d6f4ceaf9f102d6e..a1aeb727a2b0cb3813818d42b66ff78baeaac4f2 100644 (file)
--- a/src/set.c
+++ b/src/set.c
@@ -37,6 +37,15 @@ void set_free(Set* s) {
         hashmap_free(MAKE_HASHMAP(s));
 }
 
+void set_free_free(Set *s) {
+        void *p;
+
+        while ((p = set_steal_first(s)))
+                free(p);
+
+        set_free(s);
+}
+
 int set_ensure_allocated(Set **s, hash_func_t hash_func, compare_func_t compare_func) {
         return hashmap_ensure_allocated((Hashmap**) s, hash_func, compare_func);
 }
index dd2e91dd11df5cd5b426e6f66605725392ff5678..c643a2789cf95ae5989038a76756089daafe68ed 100644 (file)
--- a/src/set.h
+++ b/src/set.h
@@ -34,6 +34,7 @@ typedef struct Set Set;
 
 Set *set_new(hash_func_t hash_func, compare_func_t compare_func);
 void set_free(Set* s);
+void set_free_free(Set *s);
 Set* set_copy(Set *s);
 int set_ensure_allocated(Set **s, hash_func_t hash_func, compare_func_t compare_func);
 
index 3bb41a42393880dd12c3899c72a220b09131e449..229f44c1a97459e17152bca68845bf62af344382 100644 (file)
@@ -354,9 +354,7 @@ void unit_free(Unit *u) {
         free(u->meta.description);
         free(u->meta.fragment_path);
 
-        while ((t = set_steal_first(u->meta.names)))
-                free(t);
-        set_free(u->meta.names);
+        set_free_free(u->meta.names);
 
         free(u->meta.instance);
 
@@ -402,10 +400,7 @@ static void merge_names(Unit *u, Unit *other) {
 
         complete_move(&u->meta.names, &other->meta.names);
 
-        while ((t = set_steal_first(other->meta.names)))
-                free(t);
-
-        set_free(other->meta.names);
+        set_free_free(other->meta.names);
         other->meta.names = NULL;
         other->meta.id = NULL;