Fix memory leak in test_malloc
authorIvan Maidanski <ivmai@mail.ru>
Sun, 3 Dec 2017 07:14:33 +0000 (10:14 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Mon, 11 Dec 2017 07:22:43 +0000 (10:22 +0300)
* tests/test_malloc.c (free_list): New function definition.
* tests/test_malloc.c (run_one_test): Call free_list(x) on return.

tests/test_malloc.c

index 2735e6b..4c7e088 100644 (file)
@@ -143,6 +143,15 @@ make_list(int m, int n)
   return cons(m, make_list(m+1, n));
 }
 
+void free_list(ln *x)
+{
+  while (x != NULL) {
+    ln *next = x -> next;
+    AO_free(x);
+    x = next;
+  }
+}
+
 /* Reverse list x, and concatenate it to y, deallocating no longer needed */
 /* nodes in x.                                                            */
 ln *
@@ -205,6 +214,7 @@ void * run_one_test(void * arg) {
     x = reverse(x, 0);
   }
   check_list(x, 1, LIST_LENGTH);
+  free_list(x);
   return arg; /* use arg to suppress compiler warning */
 }