Fixes all memory leaks with valgrind (zprf_main still has problems)