From 179d3f1e659c956cce19c43fd9cf4227abf8de7b Mon Sep 17 00:00:00 2001 From: Anton Dolozin Date: Tue, 4 Nov 2025 22:52:15 +0100 Subject: [PATCH] Memory leak plugging --- du5/a_station.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/du5/a_station.c b/du5/a_station.c index 44b8c1d..2796913 100644 --- a/du5/a_station.c +++ b/du5/a_station.c @@ -31,17 +31,20 @@ void add_target_capacity(struct station* station,const char* target, int capacit struct car* ptr = *station->tracks; int count = 0; int res = select_track(station, target); - while(count != res && ptr){ + while(ptr && ptr->next){ + if(count == res){ + break; + } ptr = ptr->next; count++; } - if(!ptr->next){ - ptr = (struct car*)calloc(capacity, sizeof(struct car)); - ptr->capacity = capacity; - strcpy(ptr->value, target); - ptr->next = NULL; + if(count < res){ + struct car* next = (struct car*)calloc(10, sizeof(struct car)); + strcpy(next->value, target); + next->capacity = capacity; + ptr->next = next; return; } ptr->capacity += capacity;