From 3bc100aab94d4ebbee7ae064834dedb080a9d0a8 Mon Sep 17 00:00:00 2001 From: Bohdan Kapliuk Date: Sun, 3 Nov 2024 17:01:29 +0200 Subject: [PATCH] cv6 --- cv6/a_station.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/cv6/a_station.c b/cv6/a_station.c index beed172..a1cea9f 100644 --- a/cv6/a_station.c +++ b/cv6/a_station.c @@ -10,10 +10,20 @@ struct station* create_station(){ } void destroy_station(struct station* station){ + void destroy_station(struct station* station) { + if (station == NULL) return; + for (int i = 0; i < station->track_count; i++) { + struct car* current = station->tracks[i]; + while (current != NULL) { + struct car* temp = current; + current = current->next; + free(temp); + } + } + free(station->tracks); - free(station->track_count); - station->tracks = NULL; - station->track_count = NULL; + free(station); +} } int select_track(struct station* station, const char* target){