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;
|
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 && ptr){
|
while(ptr && ptr->next){
|
||||||
|
if(count == res){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
ptr = ptr->next;
|
ptr = ptr->next;
|
||||||
count++;
|
count++;
|
||||||
|
|
||||||
}
|
}
|
||||||
if(!ptr->next){
|
if(count < res){
|
||||||
ptr = (struct car*)calloc(capacity, sizeof(struct car));
|
struct car* next = (struct car*)calloc(10, sizeof(struct car));
|
||||||
ptr->capacity = capacity;
|
strcpy(next->value, target);
|
||||||
strcpy(ptr->value, target);
|
next->capacity = capacity;
|
||||||
ptr->next = NULL;
|
ptr->next = next;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ptr->capacity += capacity;
|
ptr->capacity += capacity;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user