diff --git a/main.c b/main.c index 2d6c200..a4f4f21 100644 --- a/main.c +++ b/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); + } } }