From: Jérôme Benoit Date: Tue, 28 Feb 2017 14:28:06 +0000 (+0100) Subject: TP_8 exo3: Properly free the memory on all elements of the linked list. X-Git-Url: https://git.piment-noir.org/?p=TD_C.git;a=commitdiff_plain;h=00d88568ddfaf33eca5b6bac058b4e5ada15cc41 TP_8 exo3: Properly free the memory on all elements of the linked list. Signed-off-by: Jérôme Benoit --- diff --git a/TP_8/exo3/exo3.c b/TP_8/exo3/exo3.c index 6c2d6c5..2c433a5 100644 --- a/TP_8/exo3/exo3.c +++ b/TP_8/exo3/exo3.c @@ -55,7 +55,12 @@ int list_get(link_t* head, unsigned index) { } void list_clear(link_t* link) { - free(link); + + while (link != NULL) { + link_t* next_link = link; + free(link); + link = next_link; + } } int main() {