tests: cleanup tests and avoid leaks

It's important to have no leaks in tests. Otherwise, we cannot
distinguish irrelevant leaks from actual bugs in valgrind.

Do some cleanup.
1 file changed