diff options
author | Adam Spragg <adam@spra.gg> | 2022-12-05 14:00:45 +0000 |
---|---|---|
committer | Adam Spragg <adam@spra.gg> | 2022-12-05 14:00:45 +0000 |
commit | 7bc3422dfece0f30cd0747e2449e7169ffdc11ed (patch) | |
tree | 5aa8a70711db83ea902e37e92aacbff45d15555c | |
parent | 4f5a4920182eb904eabd09db7cc2c70cadd603cc (diff) |
Only compile in code if it's used, and free memory when done
-rw-r--r-- | 5.c | 17 |
1 files changed, 17 insertions, 0 deletions
@@ -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; } |