Exhaust the linked list and free remaining nodes.

This commit is contained in:
Jacob Windle 2020-01-14 09:01:00 -05:00
parent bdca3cf572
commit e8e14eab28

11
main.c
View File

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