summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Spragg <adam@spra.gg>2022-12-05 14:00:45 +0000
committerAdam Spragg <adam@spra.gg>2022-12-05 14:00:45 +0000
commit7bc3422dfece0f30cd0747e2449e7169ffdc11ed (patch)
tree5aa8a70711db83ea902e37e92aacbff45d15555c
parent4f5a4920182eb904eabd09db7cc2c70cadd603cc (diff)
Only compile in code if it's used, and free memory when done
-rw-r--r--5.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/5.c b/5.c
index f404440..993c555 100644
--- a/5.c
+++ b/5.c
@@ -13,6 +13,16 @@ struct crate {
};
+void
+crate_free(struct crate * c)
+{
+ if (!c)
+ return;
+ crate_free(c->next);
+ free(c);
+}
+
+
int
crates_move_9000(struct crate ** stack, int stacks, int dest, int src, int count)
{
@@ -78,6 +88,7 @@ crates_move_9001(struct crate ** stack, int stacks, int dest, int src, int count
}
+#ifdef CRATES_DUMP
int
crates_dump(struct crate ** stack, int stacks)
{
@@ -96,6 +107,7 @@ crates_dump(struct crate ** stack, int stacks)
return 0;
}
+#endif
int
@@ -184,6 +196,11 @@ main(int argc, char ** argv)
}
fputc('\n', stdout);
+ for (i = 0; i < stacks; ++i) {
+ crate_free(stack[i]);
+ }
+ free(stack);
+
return 0;
}