Fix unit test memory leaks