From d6ecce40f9d7e1df823685bf78405143f92f6656 Mon Sep 17 00:00:00 2001 From: "Peter J. Holzer" Date: Sat, 24 Oct 2020 01:52:00 +0200 Subject: [PATCH] Free list after each test --- c/linked-list.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/c/linked-list.c b/c/linked-list.c index 2b5e984..b7ce946 100644 --- a/c/linked-list.c +++ b/c/linked-list.c @@ -58,6 +58,17 @@ resultT traverse(nodeT *p) { } } +void teardown(nodeT *p) { + nodeT *first = p; + do { + nodeT *next = p->next; + p->value = 0; + p->next = NULL; + free(p); + p = next; + } while (p != first); +} + int main (void) { size_t n; for (n = 2; ; n *= 2) { @@ -65,5 +76,6 @@ int main (void) { resultT r = traverse(p); printf("%zu %zu %g %g %" PRIuFAST64 "\n", n, r.count, r.total_time, r.avg_time, r.sum); + teardown(p); } }