Fixed a bunch of the memory leaks.

Some still remain, however........:o
Still this is a major improvement. Instead of eating like 3K of memory on tests/function.pu, it now wastes only 9 bytes. I will track those down eventually, though.