test: Fix memory leaks