Add global event list destructor

This commit is contained in:
Vftdan 2024-08-15 21:26:21 +02:00
parent 5875575d0b
commit c2a723098f
3 changed files with 14 additions and 0 deletions

View File

@ -72,3 +72,15 @@ event_destroy(EventNode * self)
self->next = NULL; self->next = NULL;
free(self); free(self);
} }
void event_destroy_all()
{
EventNode *ev;
while ((ev = FIRST_EVENT) != &END_EVENTS) {
event_destroy(ev);
if (ev == FIRST_EVENT) {
fprintf(stderr, "Broken doubly linked event list invariant\n");
abort();
}
}
}

View File

@ -47,5 +47,6 @@ extern EventNode END_EVENTS;
size_t event_replicate(EventNode * source, size_t count); size_t event_replicate(EventNode * source, size_t count);
EventNode * event_create(const EventData * content); EventNode * event_create(const EventData * content);
void event_destroy(EventNode * self); void event_destroy(EventNode * self);
void event_destroy_all();
#endif /* end of include guard: EVENTS_H_ */ #endif /* end of include guard: EVENTS_H_ */

1
main.c
View File

@ -82,6 +82,7 @@ main(int argc, char ** argv)
for (ssize_t i = loaded_config.nodes.length - 1; i >= 0; --i) { for (ssize_t i = loaded_config.nodes.length - 1; i >= 0; --i) {
graph_node_delete(nodes[i]); graph_node_delete(nodes[i]);
} }
event_destroy_all();
free(channels); free(channels);
free(nodes); free(nodes);