From 00d88568ddfaf33eca5b6bac058b4e5ada15cc41 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Tue, 28 Feb 2017 15:28:06 +0100 Subject: [PATCH] TP_8 exo3: Properly free the memory on all elements of the linked list. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- TP_8/exo3/exo3.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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() { -- 2.34.1