Add set/hashmap helpers for non-trivial freeing and use where straighforward

A macro is needed because otherwise we couldn't ensure type safety.
Some simple tests are included.
No functional change intended.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2017-11-28 21:30:30 +01:00
parent ec1d290903
commit 224b0e7ad0
19 changed files with 106 additions and 114 deletions
+3 -8
View File
@@ -1864,20 +1864,15 @@ int main(int argc, char *argv[]) {
log_error_errno(r, "Failed to write files: %m");
finish:
while ((i = hashmap_steal_first(groups)))
item_free(i);
while ((i = hashmap_steal_first(users)))
item_free(i);
hashmap_free_with_destructor(groups, item_free);
hashmap_free_with_destructor(users, item_free);
while ((n = hashmap_first_key(members))) {
strv_free(hashmap_steal_first(members));
free(n);
}
hashmap_free(groups);
hashmap_free(users);
hashmap_free(members);
hashmap_free(todo_uids);
hashmap_free(todo_gids);