Fixing the memory problems

This commit is contained in:
Anton Dolozin 2025-11-04 22:44:01 +01:00
parent 5ecd7d42c7
commit f3bc8d31ad

View File

@ -31,13 +31,13 @@ void add_target_capacity(struct station* station,const char* target, int capacit
struct car* ptr = *station->tracks; struct car* ptr = *station->tracks;
int count = 0; int count = 0;
int res = select_track(station, target); int res = select_track(station, target);
while(count != res){ while(count != res && ptr){
ptr = ptr->next; ptr = ptr->next;
count++; count++;
} }
if(!ptr){ if(!ptr->next){
ptr = (struct car*)calloc(capacity, sizeof(struct car)); ptr = (struct car*)calloc(capacity, sizeof(struct car));
ptr->capacity = capacity; ptr->capacity = capacity;
strcpy(ptr->value, target); strcpy(ptr->value, target);