TP_8 exo3: Fix the linked list freeing function to properly go to the next link.
[TD_C.git] / TP_8 / exo3 / exo3.c
index 18b065181cf5b65c6467b5e9c584ea65a5e2fe78..6f9cb34c228bae34b4c0e72160e629e0bac04ccf 100644 (file)
@@ -45,7 +45,7 @@ unsigned list_count(link_t* head) {
 int list_get(link_t* head, unsigned index) {
     
     if (index < list_count(head)) {
-        for (int i = 0; i < index; i++) {
+        for (unsigned i = 0; i < index; i++) {
             head = head->next; 
         }
         return head->value;
@@ -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->next;
+        free(link);
+        link = next_link;
+    }
 }
 
 int main() {