Memory leak plugging
This commit is contained in:
parent
f3bc8d31ad
commit
179d3f1e65
@ -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;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user