Exhaust the linked list and free remaining nodes.
This commit is contained in:
parent
bdca3cf572
commit
e8e14eab28
11
main.c
11
main.c
@ -115,7 +115,7 @@ void showHosts()
|
||||
int read_config_file() {
|
||||
// increment the refcount for tmp.
|
||||
FILE *config = fopen(CONFIG, "r");
|
||||
LinkedList *ptr = hosts;
|
||||
LinkedList *ptr = hosts, *prev = NULL;
|
||||
|
||||
char buf[1024];
|
||||
|
||||
@ -145,6 +145,15 @@ int read_config_file() {
|
||||
linkedlist_add(&hosts, buf);
|
||||
}
|
||||
}
|
||||
|
||||
// If we didn't exhaust the linked list, then we need to free any remaining nodes because the list
|
||||
// shortened.
|
||||
while (ptr != NULL) {
|
||||
prev = ptr;
|
||||
ptr = ptr->next;
|
||||
free(prev->data);
|
||||
free(prev);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user