Memory leak plugging

This commit is contained in:
Anton Dolozin 2025-11-04 22:52:15 +01:00
parent f3bc8d31ad
commit 179d3f1e65

View File

@ -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;