tests: release memory before error exits.

this makes it easier to valgrind the error cases as well.
4 files changed