diff options
author | Lennart Poettering <lennart@poettering.net> | 2010-06-15 02:45:26 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2010-06-15 02:45:26 +0200 |
commit | 53ec43c61d2f0e19c41640c63ec034b2f8cedb89 (patch) | |
tree | b541638dcdc95a7083a3db37fa1b693f1d8866a2 | |
parent | 3930341a76d2f13e25d59baba4eafaf075e8ffeb (diff) |
set: introduce set_free_free()
-rw-r--r-- | src/load-fragment.c | 6 | ||||
-rw-r--r-- | src/set.c | 9 | ||||
-rw-r--r-- | src/set.h | 1 | ||||
-rw-r--r-- | src/unit.c | 9 |
4 files changed, 13 insertions, 12 deletions
diff --git a/src/load-fragment.c b/src/load-fragment.c index 5f5e37397b..b679fab479 100644 --- a/src/load-fragment.c +++ b/src/load-fragment.c @@ -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) @@ -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); } @@ -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); diff --git a/src/unit.c b/src/unit.c index 3bb41a4239..229f44c1a9 100644 --- a/src/unit.c +++ b/src/unit.c @@ -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; |