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
+2 -11
View File
@@ -92,19 +92,10 @@ static void connection_free(Connection *c) {
}
static void context_free(Context *context) {
sd_event_source *es;
Connection *c;
assert(context);
while ((es = set_steal_first(context->listen)))
sd_event_source_unref(es);
while ((c = set_first(context->connections)))
connection_free(c);
set_free(context->listen);
set_free(context->connections);
set_free_with_destructor(context->listen, sd_event_source_unref);
set_free_with_destructor(context->connections, connection_free);
sd_event_unref(context->event);
sd_resolve_unref(context->resolve);